Change doc info
authorJeroen van der Heijden <jeroen@transceptor.technology>
Fri, 12 Oct 2018 11:05:46 +0000 (13:05 +0200)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Fri, 12 Oct 2018 11:05:46 +0000 (13:05 +0200)
205 files changed:
ChangeLog
Debug/makefile
Debug/sources.mk
Debug/src/siri/admin/subdir.mk [deleted file]
Debug/src/siri/service/subdir.mk [new file with mode: 0644]
Debug/src/slist/subdir.mk [deleted file]
Debug/src/strextra/subdir.mk [deleted file]
Release/makefile
Release/sources.mk
Release/src/siri/admin/subdir.mk [deleted file]
Release/src/siri/service/subdir.mk [new file with mode: 0644]
Release/src/slist/subdir.mk [deleted file]
Release/src/strextra/subdir.mk [deleted file]
archive/ChangeLog-2.0.13
archive/ChangeLog-2.0.16
docs/uml/siridb_class_diagram.uxf
include/argparse/argparse.h
include/cexpr/cexpr.h
include/cfgparser/cfgparser.h
include/ctree/ctree.h
include/expr/expr.h
include/imap/imap.h
include/iso8601/iso8601.h
include/llist/llist.h
include/lock/lock.h
include/logger/logger.h
include/owcrypt/owcrypt.h
include/procinfo/procinfo.h
include/qpack/qpack.h
include/siri/admin/account.h [deleted file]
include/siri/admin/client.h [deleted file]
include/siri/admin/request.h [deleted file]
include/siri/args/args.h
include/siri/async.h
include/siri/backup.h
include/siri/buffersync.h
include/siri/cfg/cfg.h
include/siri/db/access.h
include/siri/db/aggregate.h
include/siri/db/auth.h
include/siri/db/buffer.h
include/siri/db/db.h
include/siri/db/ffile.h
include/siri/db/fifo.h
include/siri/db/forward.h
include/siri/db/group.h
include/siri/db/groups.h
include/siri/db/initsync.h
include/siri/db/insert.h
include/siri/db/listener.h
include/siri/db/lookup.h
include/siri/db/median.h
include/siri/db/misc.h
include/siri/db/nodes.h
include/siri/db/pcache.h
include/siri/db/points.h
include/siri/db/pool.h
include/siri/db/pools.h
include/siri/db/presuf.h
include/siri/db/props.h
include/siri/db/queries.h
include/siri/db/query.h
include/siri/db/re.h
include/siri/db/reindex.h
include/siri/db/replicate.h
include/siri/db/series.h
include/siri/db/server.h
include/siri/db/servers.h
include/siri/db/shard.h
include/siri/db/shards.h
include/siri/db/tasks.h
include/siri/db/time.h
include/siri/db/user.h
include/siri/db/users.h
include/siri/db/variance.h
include/siri/db/walker.h
include/siri/err.h
include/siri/file/handler.h
include/siri/file/pointer.h
include/siri/grammar/gramp.h
include/siri/heartbeat.h
include/siri/help/help.h
include/siri/net/bserver.h
include/siri/net/clserver.h
include/siri/net/pipe.h
include/siri/net/pkg.h
include/siri/net/promise.h
include/siri/net/promises.h
include/siri/net/protocol.h
include/siri/net/stream.h
include/siri/net/tcp.h
include/siri/optimize.h
include/siri/service/account.h [new file with mode: 0644]
include/siri/service/client.h [new file with mode: 0644]
include/siri/service/request.h [new file with mode: 0644]
include/siri/siri.h
include/siri/version.h
include/slist/slist.h [deleted file]
include/strextra/strextra.h [deleted file]
include/timeit/timeit.h
include/vec/vec.h [new file with mode: 0644]
include/xmath/xmath.h
include/xpath/xpath.h
include/xstr/xstr.h [new file with mode: 0644]
itest/Dockerfile
itest/testing/constants.py
itest/testing/siridb.py
main.c
src/argparse/argparse.c
src/cexpr/cexpr.c
src/cfgparser/cfgparser.c
src/ctree/ctree.c
src/expr/expr.c
src/imap/imap.c
src/iso8601/iso8601.c
src/llist/llist.c
src/lock/lock.c
src/logger/logger.c
src/owcrypt/owcrypt.c
src/procinfo/procinfo.c
src/qpack/qpack.c
src/siri/admin/account.c [deleted file]
src/siri/admin/client.c [deleted file]
src/siri/admin/request.c [deleted file]
src/siri/args/args.c
src/siri/async.c
src/siri/backup.c
src/siri/buffersync.c
src/siri/cfg/cfg.c
src/siri/db/access.c
src/siri/db/aggregate.c
src/siri/db/auth.c
src/siri/db/buffer.c
src/siri/db/db.c
src/siri/db/ffile.c
src/siri/db/fifo.c
src/siri/db/forward.c
src/siri/db/group.c
src/siri/db/groups.c
src/siri/db/initsync.c
src/siri/db/insert.c
src/siri/db/listener.c
src/siri/db/lookup.c
src/siri/db/median.c
src/siri/db/misc.c
src/siri/db/nodes.c
src/siri/db/pcache.c
src/siri/db/points.c
src/siri/db/pool.c
src/siri/db/pools.c
src/siri/db/presuf.c
src/siri/db/props.c
src/siri/db/queries.c
src/siri/db/query.c
src/siri/db/re.c
src/siri/db/reindex.c
src/siri/db/replicate.c
src/siri/db/series.c
src/siri/db/server.c
src/siri/db/servers.c
src/siri/db/shard.c
src/siri/db/shards.c
src/siri/db/tasks.c
src/siri/db/time.c
src/siri/db/user.c
src/siri/db/users.c
src/siri/db/variance.c
src/siri/db/walker.c
src/siri/err.c
src/siri/file/handler.c
src/siri/file/pointer.c
src/siri/heartbeat.c
src/siri/help/help.c
src/siri/net/bserver.c
src/siri/net/clserver.c
src/siri/net/pipe.c
src/siri/net/pkg.c
src/siri/net/promise.c
src/siri/net/promises.c
src/siri/net/protocol.c
src/siri/net/stream.c
src/siri/net/tcp.c
src/siri/optimize.c
src/siri/service/account.c [new file with mode: 0644]
src/siri/service/client.c [new file with mode: 0644]
src/siri/service/request.c [new file with mode: 0644]
src/siri/siri.c
src/siri/version.c
src/slist/slist.c [deleted file]
src/strextra/strextra.c [deleted file]
src/timeit/timeit.c
src/vec/vec.c [new file with mode: 0644]
src/xmath/xmath.c
src/xpath/xpath.c
src/xstr/xstr.c [new file with mode: 0644]
test/test_aggr/sources
test/test_imap/sources
test/test_imap/test_imap.c
test/test_siridb/sources
test/test_slist/sources
test/test_slist/test_slist.c
test/test_strx/sources [deleted file]
test/test_strx/test_strx.c [deleted file]
test/test_xstr/sources [new file with mode: 0644]
test/test_xstr/test_xstr.c [new file with mode: 0644]

index 2404f1a7782d3ad07895594eab1674dec4c6c35d..b4ce4871483784e8ecb084d37cba3a998da2d575 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -235,7 +235,7 @@ siridb-server (2.0.16) xenial; urgency=medium
     SiriDB Admin Tool can be used to talk with the new API and provides both a
     command-line and a graphical web interface. Pre-compiled versions for
     different platforms can be found and downloaded from:
-    https://github.com/transceptor-technology/siridb-admin/releases/latest
+    https://github.com/transceptor-technology/siridb-service/releases/latest
 
   * Added version check before creating a new pool or replica. (issue #62)
 
@@ -281,7 +281,7 @@ siridb-server (2.0.14) xenial; urgency=medium
 
 siridb-server (2.0.13) xenial; urgency=medium
 
-  * Fixed wrapping imap to slist functions with appropriate locks.
+  * Fixed wrapping imap to vec functions with appropriate locks.
     (see issue #51)
 
  -- Jeroen van der Heijden <jeroen@transceptor.technology>  Fri, 17 Feb 2017 13:46:53 +0000
index 8468883744c94380d4d166341f2957463cc60175..49e7070f4b4dde88c3de52f096f60966a38a7bb7 100644 (file)
@@ -11,9 +11,9 @@ RM := rm -rf
 -include src/xpath/subdir.mk
 -include src/xmath/subdir.mk
 -include src/timeit/subdir.mk
--include src/strextra/subdir.mk
--include src/slist/subdir.mk
--include src/siri/admin/subdir.mk
+-include src/xstr/subdir.mk
+-include src/vec/subdir.mk
+-include src/siri/service/subdir.mk
 -include src/siri/parser/subdir.mk
 -include src/siri/net/subdir.mk
 -include src/siri/help/subdir.mk
index 56efddac8762d37345a1d489af259663cdfcb5af..6cf8c6aa0c5dff2efc0958fc0ed61c36ef7cc552 100644 (file)
@@ -27,7 +27,7 @@ src/logger \
 src/owcrypt \
 src/procinfo \
 src/qpack \
-src/siri/admin \
+src/siri/service \
 src/siri/args \
 src/siri \
 src/siri/cfg \
@@ -36,8 +36,8 @@ src/siri/file \
 src/siri/grammar \
 src/siri/help \
 src/siri/net \
-src/slist \
-src/strextra \
+src/vec \
+src/xstr \
 src/timeit \
 src/xmath \
 src/xpath \
diff --git a/Debug/src/siri/admin/subdir.mk b/Debug/src/siri/admin/subdir.mk
deleted file mode 100644 (file)
index c297bca..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-C_SRCS += \
-../src/siri/admin/account.c \
-../src/siri/admin/client.c \
-../src/siri/admin/request.c
-
-OBJS += \
-./src/siri/admin/account.o \
-./src/siri/admin/client.o \
-./src/siri/admin/request.o
-
-C_DEPS += \
-./src/siri/admin/account.d \
-./src/siri/admin/client.d \
-./src/siri/admin/request.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/siri/admin/%.o: ../src/siri/admin/%.c
-       @echo 'Building file: $<'
-       @echo 'Invoking: GCC C Compiler'
-       gcc -I../include -O0 -g3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
-       @echo 'Finished building: $<'
-       @echo ' '
-
-
diff --git a/Debug/src/siri/service/subdir.mk b/Debug/src/siri/service/subdir.mk
new file mode 100644 (file)
index 0000000..1596e98
--- /dev/null
@@ -0,0 +1,30 @@
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables
+C_SRCS += \
+../src/siri/service/account.c \
+../src/siri/service/client.c \
+../src/siri/service/request.c
+
+OBJS += \
+./src/siri/service/account.o \
+./src/siri/service/client.o \
+./src/siri/service/request.o
+
+C_DEPS += \
+./src/siri/service/account.d \
+./src/siri/service/client.d \
+./src/siri/service/request.d
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/siri/service/%.o: ../src/siri/service/%.c
+       @echo 'Building file: $<'
+       @echo 'Invoking: GCC C Compiler'
+       gcc -I../include -O0 -g3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
+       @echo 'Finished building: $<'
+       @echo ' '
+
+
diff --git a/Debug/src/slist/subdir.mk b/Debug/src/slist/subdir.mk
deleted file mode 100644 (file)
index f7a6549..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-C_SRCS += \
-../src/slist/slist.c
-
-OBJS += \
-./src/slist/slist.o
-
-C_DEPS += \
-./src/slist/slist.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/slist/%.o: ../src/slist/%.c
-       @echo 'Building file: $<'
-       @echo 'Invoking: GCC C Compiler'
-       gcc -I../include -O0 -g3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
-       @echo 'Finished building: $<'
-       @echo ' '
-
-
diff --git a/Debug/src/strextra/subdir.mk b/Debug/src/strextra/subdir.mk
deleted file mode 100644 (file)
index 8024300..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-C_SRCS += \
-../src/strextra/strextra.c
-
-OBJS += \
-./src/strextra/strextra.o
-
-C_DEPS += \
-./src/strextra/strextra.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/strextra/%.o: ../src/strextra/%.c
-       @echo 'Building file: $<'
-       @echo 'Invoking: GCC C Compiler'
-       gcc -I../include -O0 -g3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
-       @echo 'Finished building: $<'
-       @echo ' '
-
-
index 8769767d709fdae330198170225b11e25140a333..fc01f5314b46d9ed521047fe2801f49b89b1f33e 100644 (file)
@@ -11,9 +11,9 @@ RM := rm -rf
 -include src/xpath/subdir.mk
 -include src/xmath/subdir.mk
 -include src/timeit/subdir.mk
--include src/strextra/subdir.mk
--include src/slist/subdir.mk
--include src/siri/admin/subdir.mk
+-include src/xstr/subdir.mk
+-include src/vec/subdir.mk
+-include src/siri/service/subdir.mk
 -include src/siri/parser/subdir.mk
 -include src/siri/net/subdir.mk
 -include src/siri/help/subdir.mk
index 56efddac8762d37345a1d489af259663cdfcb5af..6cf8c6aa0c5dff2efc0958fc0ed61c36ef7cc552 100644 (file)
@@ -27,7 +27,7 @@ src/logger \
 src/owcrypt \
 src/procinfo \
 src/qpack \
-src/siri/admin \
+src/siri/service \
 src/siri/args \
 src/siri \
 src/siri/cfg \
@@ -36,8 +36,8 @@ src/siri/file \
 src/siri/grammar \
 src/siri/help \
 src/siri/net \
-src/slist \
-src/strextra \
+src/vec \
+src/xstr \
 src/timeit \
 src/xmath \
 src/xpath \
diff --git a/Release/src/siri/admin/subdir.mk b/Release/src/siri/admin/subdir.mk
deleted file mode 100644 (file)
index ee5fbfb..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-C_SRCS += \
-../src/siri/admin/account.c \
-../src/siri/admin/client.c \
-../src/siri/admin/request.c
-
-OBJS += \
-./src/siri/admin/account.o \
-./src/siri/admin/client.o \
-./src/siri/admin/request.o
-
-C_DEPS += \
-./src/siri/admin/account.d \
-./src/siri/admin/client.d \
-./src/siri/admin/request.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/siri/args/%.o: ../src/siri/args/%.c
-       @echo 'Building file: $<'
-       @echo 'Invoking: GCC C Compiler'
-       gcc -DNDEBUG -I../include -O3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
-       @echo 'Finished building: $<'
-       @echo ' '
-
-
diff --git a/Release/src/siri/service/subdir.mk b/Release/src/siri/service/subdir.mk
new file mode 100644 (file)
index 0000000..12a186e
--- /dev/null
@@ -0,0 +1,30 @@
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables
+C_SRCS += \
+../src/siri/service/account.c \
+../src/siri/service/client.c \
+../src/siri/service/request.c
+
+OBJS += \
+./src/siri/service/account.o \
+./src/siri/service/client.o \
+./src/siri/service/request.o
+
+C_DEPS += \
+./src/siri/service/account.d \
+./src/siri/service/client.d \
+./src/siri/service/request.d
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/siri/args/%.o: ../src/siri/args/%.c
+       @echo 'Building file: $<'
+       @echo 'Invoking: GCC C Compiler'
+       gcc -DNDEBUG -I../include -O3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
+       @echo 'Finished building: $<'
+       @echo ' '
+
+
diff --git a/Release/src/slist/subdir.mk b/Release/src/slist/subdir.mk
deleted file mode 100644 (file)
index e16a3cc..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-C_SRCS += \
-../src/slist/slist.c
-
-OBJS += \
-./src/slist/slist.o
-
-C_DEPS += \
-./src/slist/slist.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/slist/%.o: ../src/slist/%.c
-       @echo 'Building file: $<'
-       @echo 'Invoking: GCC C Compiler'
-       gcc -DNDEBUG -I../include -O3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
-       @echo 'Finished building: $<'
-       @echo ' '
-
-
diff --git a/Release/src/strextra/subdir.mk b/Release/src/strextra/subdir.mk
deleted file mode 100644 (file)
index 7691047..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-C_SRCS += \
-../src/strextra/strextra.c
-
-OBJS += \
-./src/strextra/strextra.o
-
-C_DEPS += \
-./src/strextra/strextra.d
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/strextra/%.o: ../src/strextra/%.c
-       @echo 'Building file: $<'
-       @echo 'Invoking: GCC C Compiler'
-       gcc -DNDEBUG -I../include -O3 -Wall -Wextra $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
-       @echo 'Finished building: $<'
-       @echo ' '
-
-
index 8eda7e54c4a2060deea09086bccbed0a7a6d3b3b..57939c1690a918af799ecc248d10afb692a49028 100644 (file)
@@ -1,2 +1,2 @@
-  * Fixed wrapping imap to slist functions with appropriate locks. 
+  * Fixed wrapping imap to vec functions with appropriate locks. 
     (see issue #51)
\ No newline at end of file
index 9a3305446d1523b2886ec838d1ab0d0c5076d6f9..f057e811ba0c28592fd00d45019afa23b2d18792 100644 (file)
@@ -17,6 +17,6 @@
     SiriDB Admin Tool can be used to talk with the new API and provides both a 
     command-line and a graphical web interface. Pre-compiled versions for 
     different platforms can be found and downloaded from:
-    https://github.com/transceptor-technology/siridb-admin/releases/latest
+    https://github.com/transceptor-technology/siridb-service/releases/latest
     
   * Added version check before creating a new pool or replica. (issue #62)
\ No newline at end of file
index 3692ec387e803bfca57f694040f4557448c65e38..84a60a57f28cdf554d2af8cad1993bb4c01e7014 100644 (file)
@@ -148,7 +148,7 @@ siridb_servers_get_file(): ssize_t
 siridb_servers_list(): int
 siridb_servers_load(): int
 siridb_servers_online(): int
-siridb_servers_other2slist(): *slist_t
+siridb_servers_other2vec(): *vec_t
 siridb_servers_register(): int
 siridb_servers_save(): int
 siridb_servers_send_flags(): void
@@ -566,8 +566,8 @@ flags: uint8_t
 fn: *char
 groups: *ct_t
 mutex: uv_mutex_t 
-ngroups: *slist_t
-nseries: *slist_t
+ngroups: *vec_t
+nseries: *vec_t
 ref: uint8_t
 status: uint8_t
 work: uv_work_t
@@ -614,7 +614,7 @@ name: *char
 ref: uint16_t
 regex: *pcre 
 regex_extra: *pcre_extra
-series: *slist_t
+series: *vec_t
 source: *char
 --
 siridb__group_decref(): void
index 199c04fcce3415f6ad6212851a9c55918acb16fb..8a96636d12f40363911d18edc8528be09f8ce9e3 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * argparse.h - module for parsing command line arguments.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * argparse.h - Module for parsing command line arguments.
  */
 #ifndef ARGPARSE_H_
 #define ARGPARSE_H_
index c87c801201785be59e16fba2aae4f20ed7adf66c..a74d0bff4b758aa715da8e5802f11bc3c4c145e6 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * cexpr.h - Conditional expressions.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-06-2016
- *
  */
 #ifndef CEXPR_H_
 #define CEXPR_H_
index bf6478a47f9351d9166eca7e471f350855317726..938ebebde0b993fe2ad73617b448df19f2ddb8ef 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * cfgparser.h - module for reading (and later writing) to INI style files.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * cfgparser.h - Reading (and later writing) to INI style files.
  */
 #ifndef CFGPARSER_H_
 #define CFGPARSER_H_
index 4d0cd2af7e3df043cce7ffe7d4755124d5f8e82f..144ff4162886ace76d0ad43e0b11ea66d4010201 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * ctree.h - Compact Binary Tree implementation.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-03-2016
- *
  */
 #ifndef CTREE_H_
 #define CTREE_H_
index 6f25865ce5e91a97575cf4aaa873fbf81da00e8e..4a297540c2efed04cfc2ab5875ae1bfb9d2b5853 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * expr.h - Parse expression
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 19-04-2016
- *
+ * expr.h - For parsing expressions.
  */
 #ifndef EXPR_H_
 #define EXPR_H_
index 42e92d71d0b142540a7873a2110608d82051568b..f6e72b47c984ca91f6f9df428e18b90ac3a76e95 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * imap.h - map for uint64_t integer keys
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 03-08-2016
- *
+ * imap.h - Lookup map for uint64_t integer keys with set operation support.
  */
 #ifndef IMAP_H_
 #define IMAP_H_
@@ -17,7 +9,7 @@ typedef struct imap_s imap_t;
 
 #include <inttypes.h>
 #include <stddef.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 
 typedef int (*imap_cb)(void * data, void * args);
 typedef int (*imap_free_cb)(void * data);
@@ -35,10 +27,10 @@ void * imap_get(imap_t * imap, uint64_t id);
 void * imap_pop(imap_t * imap, uint64_t id);
 int imap_walk(imap_t * imap, imap_cb cb, void * data);
 void imap_walkn(imap_t * imap, size_t * n, imap_cb cb, void * data);
-slist_t * imap_slist(imap_t * imap);
-slist_t * imap_slist_pop(imap_t * imap);
-slist_t * imap_2slist(imap_t * imap);
-slist_t * imap_2slist_ref(imap_t * imap);
+vec_t * imap_vec(imap_t * imap);
+vec_t * imap_vec_pop(imap_t * imap);
+vec_t * imap_2vec(imap_t * imap);
+vec_t * imap_2vec_ref(imap_t * imap);
 void imap_union_ref(
         imap_t * dest,
         imap_t * imap,
@@ -67,7 +59,7 @@ struct imap_node_s
 struct imap_s
 {
     size_t len;
-    slist_t * slist;
+    vec_t * vec;
     imap_node_t nodes[];
 };
 
index 36c16999cb564f8fe9a11dd91fb328525e8b1e62..40d09e1e3a8f827f956c54616670b0d530071bbd 100644 (file)
@@ -1,13 +1,6 @@
 /*
- * iso8601.h - Library to parse ISO 8601 dates
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 21-04-2016
- *
+ * iso8601.h - Library to parse ISO 8601 dates. Time-zones are found with
+ *             tzset() in either /usr/lib/zoneinfo/ or /usr/share/zoneinfo/.
  */
 #ifndef ISO8601_H_
 #define ISO8601_H_
index 48f65e5112acea30979bb4fb9c4f70570826f418..e5c57250f1f9761635d526b57a53133d896a7f30 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * llist.h - Linked List
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 03-05-2016
- *
+ * llist.h - Linked List implementation.
  */
 #ifndef LLIST_H_
 #define LLIST_H_
@@ -16,7 +8,7 @@ typedef struct llist_s llist_t;
 typedef struct llist_node_s llist_node_t;
 
 #include <stdio.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 
 typedef int (*llist_cb)(void * data, void * args);
 
@@ -25,7 +17,7 @@ void llist_free_cb(llist_t * llist, llist_cb cb, void * args);
 int llist_append(llist_t * llist, void * data);
 int llist_walk(llist_t * llist, llist_cb cb, void * args);
 void llist_walkn(llist_t * llist, size_t * n, llist_cb cb, void * args);
-slist_t * llist2slist(llist_t * llist);
+vec_t * llist2vec(llist_t * llist);
 void * llist_get(llist_t * llist, llist_cb cb, void * args);
 void * llist_remove(llist_t * llist, llist_cb cb, void * args);
 void * llist_pop(llist_t * llist);
index 359a5647a349824c184357d1a4956f76e69a0832..1d51f51caebfdbbcc3bac1ccdd0a1ab8b65904ca 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * lock.h - SiriDB Lock.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-07-2016
- *
+ * lock.h - Lock a directory by using a lock file.
  */
 #ifndef LOCK_H_
 #define LOCK_H_
index 7b03ed113c407ecc440e7c90bd3b2120f393cb58..be3d51cfe6c20b680dd25c95d3e23a1291933ed3 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * logger.h - log module
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * logger.h - Logging module.
  */
 #ifndef LOGGER_H_
 #define LOGGER_H_
index 67c00633b47d846a217c390db0094bc6d22f1329..6fff1572e171e470f15162d580762a894e6a85e5 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * owcrypt.h - One Way Encryption. (used for storing a database user password)
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 24-02-2017
- *
  */
 #ifndef OWCRYPT_H_
 #define OWCRYPT_H_
index 7ad5df705a7203bec12505cd5cb7233e3b53ce24..6a1278442e1dd682990015840c2dd0318fa573b0 100644 (file)
@@ -6,13 +6,6 @@
  * http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-
  *      memory-consumption-from-inside-a-process
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-03-2016
- *
  */
 
 #ifndef PROCINFO_H_
index a432e7023435dd623bb1838ecebbc5e2c65a2765..60e5538e2b1c5bedefec8da6fcf94cf931366bd5 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * qpack.h - efficient binary serialization format
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 11-03-2016
- *
+ * qpack.h - Efficient binary serialization format.
  */
 #ifndef QPACK_H_
 #define QPACK_H_
diff --git a/include/siri/admin/account.h b/include/siri/admin/account.h
deleted file mode 100644 (file)
index 325af9b..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * account.h - SiriDB Administrative User.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2017
- *
- */
-#ifndef SIRI_ADMIN_ACCOUNT_H_
-#define SIRI_ADMIN_ACCOUNT_H_
-
-typedef struct siri_admin_account_s siri_admin_account_t;
-
-#include <qpack/qpack.h>
-#include <siri/siri.h>
-
-int siri_admin_account_init(siri_t * siri);
-void siri_admin_account_destroy(siri_t * siri);
-int siri_admin_account_new(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        qp_obj_t * qp_password,
-        int is_encrypted,
-        char * err_msg);
-int siri_admin_account_check(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        qp_obj_t * qp_password,
-        char * err_msg);
-int siri_admin_account_change_password(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        qp_obj_t * qp_password,
-        char * err_msg);
-int siri_admin_account_drop(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        char * err_msg);
-int siri_admin_account_save(siri_t * siri, char * err_msg);
-
-struct siri_admin_account_s
-{
-    char * account;
-    char * password; /* keeps an encrypted password */
-};
-
-#endif  /* SIRI_ADMIN_ACCOUNT_H_ */
diff --git a/include/siri/admin/client.h b/include/siri/admin/client.h
deleted file mode 100644 (file)
index 91f68ee..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * client.h - Client for expanding a siridb database.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 24-03-2017
- *
- */
-#ifndef SIRI_ADMIN_CLIENT_H_
-#define SIRI_ADMIN_CLIENT_H_
-
-typedef struct siri_admin_client_s siri_admin_client_t;
-
-#include <inttypes.h>
-#include <uv.h>
-#include <qpack/qpack.h>
-#include <uuid/uuid.h>
-#include <siri/net/pkg.h>
-
-int siri_admin_client_request(
-        uint16_t pid,
-        uint16_t port,
-        int pool,
-        uuid_t * uuid,
-        qp_obj_t * host,
-        qp_obj_t * username,
-        qp_obj_t * password,
-        qp_obj_t * dbname,
-        const char * dbpath,
-        sirinet_stream_t * client,
-        char * err_msg);
-
-void siri_admin_client_free(siri_admin_client_t * adm_client);
-
-struct siri_admin_client_s
-{
-    uint8_t request;
-    uint8_t flags;
-    uint16_t pid;
-    uint16_t port;
-    uuid_t uuid;
-    int pool;  /*       -1 for a new pool       */
-    char * host;
-    char * username;
-    char * password;
-    char * dbname;
-    char * dbpath;
-    sirinet_stream_t * client;
-    sirinet_pkg_t * pkg;
-};
-
-#endif  /* SIRI_ADMIN_CLIENT_H_ */
diff --git a/include/siri/admin/request.h b/include/siri/admin/request.h
deleted file mode 100644 (file)
index c5324d8..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * request.h - SiriDB Administrative Request.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2017
- *
- */
-#ifndef SIRI_ADMIN_REQUEST_H_
-#define SIRI_ADMIN_REQUEST_H_
-
-typedef enum
-{
-    ADMIN_NEW_ACCOUNT_,
-    ADMIN_CHANGE_PASSWORD_,
-    ADMIN_DROP_ACCOUNT_,
-    ADMIN_NEW_DATABASE_,
-    ADMIN_NEW_POOL,
-    ADMIN_NEW_REPLICA,
-    ADMIN_GET_VERSION=64,
-    ADMIN_GET_ACCOUNTS,
-    ADMIN_GET_DATABASES
-} admin_request_t;
-
-#include <qpack/qpack.h>
-#include <siri/net/protocol.h>
-
-int siri_admin_request_init(void);
-void siri_admin_request_destroy(void);
-cproto_server_t siri_admin_request(
-        int tp,
-        qp_unpacker_t * qp_unpacker,
-        qp_obj_t * qp_account,
-        qp_packer_t ** packaddr,
-        uint16_t pid,
-        sirinet_stream_t * client,
-        char * err_msg);
-void siri_admin_request_rollback(const char * dbpath);
-
-
-#endif  /* SIRI_ADMIN_REQUEST_H_ */
index b1eba2b2eea897c9a6705139940ce46e0d2f5431..d756df7b8501d548ff9c1cb8bdf63f4377830c78 100644 (file)
@@ -1,12 +1,5 @@
 /*
- * args.h - SiriDB Arguments.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2017
+ * args.h - Parse SiriDB command line arguments.
  */
 #ifndef SIRI_ARGS_H_
 #define SIRI_ARGS_H_
index e41ecdb161f459ba4937dd1e05c95a85541476f2..91fc8fa56d11f96cd287ea126ca57465e3d7af5e 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * async.h - SiriDB async wrapper
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 21-07-2016
- *
+ * async.h - SiriDB async wrapper.
  */
 #ifndef SIRI_ASYC_H_
 #define SIRI_ASYC_H_
index 66c3968002cffc0efa8783320c40f4df50dea6f6..ffee84d1b16ceed3e3cf89fb78bcf86285272437 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * backup.h - Set SiriDB in backup mode.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 27-09-2016
- *
  */
 #ifndef SIRI_BACKUP_H_
 #define SIRI_BACKUP_H_
index ebc8bd68112e2c58a4701deae6540d1095b1f4b2..e41e00a866076a0f3bcfb064b95bb10d11635f7b 100644 (file)
@@ -1,10 +1,5 @@
 /*
  * buffersync.h - Buffer sync.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2018, Transceptor Technology
- *
  */
 #ifndef SIRI_BUFFERSYNC_H_
 #define SIRI_BUFFERSYNC_H_
index 0342b688e8acf38c238ddf298398a2f1400b37a0..14aab8f28b1be4fa730e7814903989b6b779e6f4 100644 (file)
@@ -1,12 +1,5 @@
 /*
- * cfg.h - SiriDB Config.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2017
+ * cfg.h - Read the global SiriDB configuration file. (usually siridb.conf)
  */
 #ifndef SIRI_CFG_H_
 #define SIRI_CFG_H_
index 0d29f08f5bcbc57b58ac5b5c585483ba0ae20ecf..8587f18d8aff38d747a79e1a90601f0289ef116f 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * access.h - Access constants and functions.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-03-2016
- *
  */
 #ifndef SIRIDB_ACCESS_H_
 #define SIRIDB_ACCESS_H_
index d2f82cb9a0ddf13a134eb6e9804f729ffc8a92ff..5b184d4e3f086d7bd1e61761828571bfb07bfb02 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * aggregate.h - SiriDB aggregation methods.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 15-04-2016
- *
  */
 #ifndef SIRIDB_AGGREGATE_H_
 #define SIRIDB_AGGREGATE_H_
@@ -16,7 +8,7 @@ typedef struct siridb_aggr_s siridb_aggr_t;
 
 #include <siri/db/points.h>
 #include <siri/grammar/gramp.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <cexpr/cexpr.h>
 #include <qpack/qpack.h>
 #include <pcre2.h>
@@ -26,8 +18,8 @@ siridb_points_t * siridb_aggregate_run(
         siridb_aggr_t * aggr,
         char * err_msg);
 void siridb_init_aggregates(void);
-slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg);
-void siridb_aggregate_list_free(slist_t * alist);
+vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg);
+void siridb_aggregate_list_free(vec_t * alist);
 int siridb_aggregate_can_skip(cleri_children_t * children);
 
 struct siridb_aggr_s
index 717168be45517dd487facb7e8d2ed5b617aeb73a..84a299baa17e126087259a7369e75ed2a7bc05fa 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * auth.h - Handle SiriDB authentication.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
  */
 #ifndef SIRIDB_AUTH_H_
 #define SIRIDB_AUTH_H_
index 7f037d7432c7585ee38c2b7e24ca1a03ff82bec2..c4df0d0ca41e6124dffc52241321817417daa9f5 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * buffer.h - Buffer for integer and double series.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 01-04-2016
- *
+ * buffer.h - Buffer for integer and double values.
  */
 #ifndef SIRIDB_BUFFER_H_
 #define SIRIDB_BUFFER_H_
@@ -47,7 +39,7 @@ struct siridb_buffer_s
     size_t len;             /* number of points allocated per series */
     char * template;        /* template for writing an empty buffer */
     char * path;            /* path where the buffer file is stored */
-    slist_t * empty;        /* list with empty buffer spaces */
+    vec_t * empty;        /* list with empty buffer spaces */
     FILE * fp;              /* buffer file pointer */
     int fd;                 /* buffer file descriptor */
 };
index a9469e7efa8faf73ab6877ec59685a764377e7e6..1fcf2448d4afa603b744d767f3bcbd4fc44f0f8a 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * db.h - contains functions and constants for a SiriDB database.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * db.h - SiriDB database.
  */
 #ifndef SIRIDB_H_
 #define SIRIDB_H_
index d36add13f38aee01ec2888f69c81e184bfe47d49..3410521ffe3686da9f2e4f0691a77115649861b7 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * ffile.h - FIFO file.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 30-06-2016
- *
  */
 #ifndef SIRIDB_FFILE_H_
 #define SIRIDB_FFILE_H_
index 6a244a42691828c1869effa5a2f6997fa5b202bb..9ca0d8ad44ae9af75e46d1483fd657bc16598015 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * fifo.h - First in, first out file buffer.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 30-06-2016
- *
  */
 #ifndef SIRIDB_FIFO_H_
 #define SIRIDB_FIFO_H_
index 34775899c60089da636e358ac285338b8843b1a6..1b2c3602c4a393822dbbaf278b1c92650ece7817 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * forward.h - Handle forwarding series while re-indexing
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 31-07-2016
- *
+ * forward.h - Handle forwarding series while re-indexing.
  */
 #ifndef SIRIDB_FORWARD_H_
 #define SIRIDB_FORWARD_H_
index b27da91602140f51cb9048f758911f6824b0ba6d..08667331b5de25ba0822857a0b083ca46b4d97c1 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * group.h - Group (saved regular expressions).
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-08-2016
- *
  */
 #ifndef SIRIDB_GROUP_H_
 #define SIRIDB_GROUP_H_
@@ -18,7 +10,7 @@
 
 typedef struct siridb_group_s siridb_group_t;
 
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <siri/db/series.h>
 #include <pcre2.h>
 
@@ -56,7 +48,7 @@ struct siridb_group_s
     uint32_t n;     /* total series (needs an update from all pools) */
     char * name;
     char * source;  /* pattern/flags representation */
-    slist_t * series;
+    vec_t * series;
     pcre2_code * regex;
     pcre2_match_data * match_data;
 };
index bc517457125ca390e78e29719e5b1d495ecc4123..523ed731a1fbbe2c80605df464e6ad47c76bd9b3 100644 (file)
@@ -1,13 +1,24 @@
 /*
  * groups.h - Groups (saved regular expressions).
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
+ * Info groups->mutex:
  *
- * changes
- *  - initial version, 16-08-2016
+ *  Main thread:
+ *      groups->groups :    read (no lock)      write (lock)
+ *      groups->nseries :   read (lock)         write (lock)
+ *      groups->ngroups :   read (lock)         write (lock)
+ *      group->series :     read (lock)         write (not allowed)
+
+ *  Other threads:
+ *      groups->groups :    read (lock)         write (not allowed)
+ *      groups->nseries :   read (lock)         write (lock)
+ *      groups->ngroups :   read (lock)         write (lock)
+ *
+ *  Group thread:
+ *      group->series :     read (no lock)      write (lock)
  *
+ *  Note:   One exception to 'not allowed' are the free functions
+ *          since they only run when no other references to the object exist.
  */
 #ifndef SIRIDB_GROUPS_H_
 #define SIRIDB_GROUPS_H_
@@ -24,7 +35,7 @@ typedef struct siridb_groups_s siridb_groups_t;
 #define GROUPS_FLAG_DROPPED_SERIES 1
 
 #include <ctree/ctree.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <uv.h>
 #include <siri/db/db.h>
 #include <siri/net/pkg.h>
@@ -58,8 +69,8 @@ struct siridb_groups_s
     uint8_t ref;
     char * fn;
     ct_t * groups;
-    slist_t * nseries;  /* list of series we need to assign to groups */
-    slist_t * ngroups;  /* list of groups which need initialization */
+    vec_t * nseries;  /* list of series we need to assign to groups */
+    vec_t * ngroups;  /* list of groups which need initialization */
     uv_mutex_t mutex;
     uv_work_t work;
 };
index 3bae179616e739f14aea78d1102cfb3029e71f5a..a76c4c82ba33efd0bca072a0ad31c03689ba306b 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * initsync.h - Initial replica synchronization
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 22-07-2016
- *
+ * initsync.h - Initial replica synchronization.
  */
 #ifndef SIRIDB_INITSYNC_H_
 #define SIRIDB_INITSYNC_H_
index 888f31ef3919657e49589411bac19d96df0bb613..e1a663e8a3f8a490acbce5a97a3ca489608ae2cb 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * insert.h - Handler database inserts.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 24-03-2016
- *
  */
 #ifndef SIRIDB_INSERT_H_
 #define SIRIDB_INSERT_H_
index c74d621f4cb0f95961c4bc80c13c4427a8a86e31..0950e7d48649158b9f87d3e44cd05011163c0292 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * listener.h - contains functions for processing queries.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * listener.h - Contains functions for processing queries.
  */
 #ifndef SIRIDB_LISTENER_H_
 #define SIRIDB_LISTENER_H_
index d58d4dfdbaa3fa9c7a3239002b48605210df9e78..ddbbdd7b802731c91a66487d616cc4f6ecfa79b2 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * lookup.h - SiriDB Pool lookup.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 29-07-2016
- *
+ * lookup.h - Find and assign to which pool series belong.
  */
 #ifndef SIRIDB_LOOKUP_H_
 #define SIRIDB_LOOKUP_H_
index e2ae8c0902cf78a5c77c5983e782f0a5e7c958ce..49f2594a655dd17d97ed8d7b134afe5ece3eccd7 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * median.h - Calculate median, median high and median low.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-04-2016
- *
  */
 #ifndef SIRIDB_MEDIAN_H_
 #define SIRIDB_MEDIAN_H_
index 67b46e255de9b1f299f7d9b9b7295b519f4a24dc..d706a03b84ccd42ad014d6d3239978e967713ad7 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * misc.h - Miscellaneous functions used by SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-08-2016
- *
  */
 #ifndef SIRIDB_MISC_H_
 #define SIRIDB_MISC_H_
index 2a4a406aace282cb4d87cf9423a3e74c3a50d4c2..c6fc62d47346caee9a4f2c3d686af245a523f28d 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * node.h - contains logic for cleri nodes which we need to parse.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * nodes.h - Contains logic for cleri nodes which we need to parse.
  */
 #ifndef SIRIDB_NODES_H_
 #define SIRIDB_NODES_H_
index efae1bc5e5b99527e54ca7198d4236d6dda8266a..ea6676f5507ed9f6d9719f18cb00d97a37ea6638 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * pcache.h - Points structure with notion or its size
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-10-2016
- *
+ * pcache.h - Points structure with notion of its size.
  */
 #ifndef SIRIDB_PCACHE_H_
 #define SIRIDB_PCACHE_H_
index 37dd6a199c1f0d1390c5ff6231856c111cbcf7e5..19172635499e8088e816e77ce39613e0d7dcf478 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * points.h - Array object for points.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-04-2016
- *
  */
 #ifndef SIRIDB_POINTS_H_
 #define SIRIDB_POINTS_H_
@@ -27,7 +19,7 @@ typedef struct siridb_points_s siridb_points_t;
 #include <stdlib.h>
 #include <inttypes.h>
 #include <qpack/qpack.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 
 void siridb_points_init(void);
 siridb_points_t * siridb_points_new(size_t size, points_tp tp);
@@ -41,7 +33,7 @@ siridb_points_t * siridb_points_copy(siridb_points_t * points);
 int siridb_points_pack(siridb_points_t * points, qp_packer_t * packer);
 void siridb_points_ts_correction(siridb_points_t * points, double factor);
 int siridb_points_raw_pack(siridb_points_t * points, qp_packer_t * packer);
-siridb_points_t * siridb_points_merge(slist_t * plist, char * err_msg);
+siridb_points_t * siridb_points_merge(vec_t * plist, char * err_msg);
 unsigned char * siridb_points_zip_double(
         siridb_points_t * points,
         uint_fast32_t start,
index c9c77b339b1a2ac24445cadbf6d92620246fd8da..c1dad29a1705c1a16ab66afcb86c43538e0d3b45 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * pool.h - Generate pool lookup.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 25-03-2016
- *
+ * pool.h - SiriDB pool containing one or two servers.
  */
 #ifndef SIRIDB_POOL_H_
 #define SIRIDB_POOL_H_
index 349e0256e196f7a67aef33c4cea45b34700e5340..6bb4691aee5f64e1cbbe6c63623c827d32fcd3aa 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * pools.h - Generate pools lookup.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 25-03-2016
- *
+ * pools.h - Collection of pools.
  */
 #ifndef SIRIDB_POOLS_H_
 #define SIRIDB_POOLS_H_
@@ -21,7 +13,7 @@ typedef struct siridb_pools_s siridb_pools_t;
 #include <siri/net/pkg.h>
 #include <siri/net/promise.h>
 #include <siri/net/promises.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <siri/db/lookup.h>
 
 void siridb_pools_init(siridb_t * siridb);
@@ -41,7 +33,7 @@ void siridb_pools_send_pkg(
         void * data,
         int flags);
 void siridb_pools_send_pkg_2some(
-        slist_t * slist,
+        vec_t * vec,
         sirinet_pkg_t * pkg,
         uint64_t timeout,
         sirinet_promises_cb cb,
index 297616d4a9d5df48e23f4afa6cc398a523b400c0..f1f9bdd1b87d3c6d18ed50047ec5137cb02b192e 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * presuf.h - Prefix and Suffix store.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-08-2016
- *
  */
 #ifndef SIRIDB_PRESUF_H_
 #define SIRIDB_PRESUF_H_
index 9bd6c1136a461169b937e5c660f0a1765eb617cf..af845b000b9db800d9fb79664077db2351339300 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * props.h - Functions to return SiriDB properties.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 17-03-2016
- *
  */
 #ifndef SIRIDB_PROPS_H_
 #define SIRIDB_PROPS_H_
index 98ff00d576de4b4c30669da38c5b560027228d9b..d47c5c428ba6a701178a9fcb8adc3c930c80886b 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * queries.h - Querie helpers for listener
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 03-05-2016
- *
+ * queries.h - Query helpers for listener.
  */
 #ifndef SIRIDB_QUERIES_H_
 #define SIRIDB_QUERIES_H_
@@ -15,7 +7,7 @@
 #include <uv.h>
 #include <inttypes.h>
 #include <imap/imap.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <cexpr/cexpr.h>
 #include <cleri/cleri.h>
 #include <ctree/ctree.h>
@@ -53,8 +45,8 @@ uint8_t flags;                  \
 imap_t * series_map;            \
 imap_t * series_tmp;            \
 imap_t * pmap;                  \
-slist_t * slist;                \
-size_t slist_index;             \
+vec_t * vec;                \
+size_t vec_index;             \
 imap_update_cb update_cb;       \
 cexpr_t * where_expr;           \
 pcre2_code * regex;             \
@@ -117,13 +109,13 @@ struct query_drop_s
 {
     QUERY_DEF
     size_t n;  /* keep a counter for number of drops.   */
-    slist_t * shards_list;
+    vec_t * shards_list;
 };
 
 struct query_list_s
 {
     QUERY_DEF
-    slist_t * props;  /* will be freed      */
+    vec_t * props;  /* will be freed      */
     size_t limit;
 };
 
@@ -138,8 +130,8 @@ struct query_select_s
     char * merge_as;
     ct_t * result;
     imap_t * points_map;    /* points_map for caching                       */
-    slist_t * alist;        /* aggregation list (can be used multiple times)*/
-    slist_t * mlist;        /* merge aggregation list                       */
+    vec_t * alist;        /* aggregation list (can be used multiple times)*/
+    vec_t * mlist;        /* merge aggregation list                       */
 };
 
 #endif  /* SIRIDB_QUERIES_H_ */
index 9990f92df134e0b0f281e6b1b662addbf0e55bf8..fbe2ef761dd1ca714001d369c5d5275d3b32f648 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * query.h - Responsible for parsing queries.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
  */
 #ifndef SIRIDB_QUERY_H_
 #define SIRIDB_QUERY_H_
index c5c5cbee5a70b202ce7ccd72b23c68e94bdfa5ff..2a9b16c91fbbe24d7a340bf2ea1d4531dbce5276 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * re.h - Helpers for regular expressions
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-08-2016
- *
+ * re.h - Helpers for regular expressions.
  */
 #ifndef SIRIDB_RE_H_
 #define SIRIDB_RE_H_
index 140b03a82649780bd81adcabe2bba8c78da00266..db80b42661af2fd408d8a673b9a95ac8751257d0 100644 (file)
@@ -1,13 +1,19 @@
 /*
  * reindex.h - SiriDB Re-index.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
+ * Differences while re-indexing:
  *
- * changes
- *  - initial version, 27-07-2016
+ *  - Group information like number of series will be updated at a lower
+ *    interval which leads to probably incorrect number of series per group.
+ *    Selections for series in a group or a list of series per group are still
+ *    correct and can only lack of brand new series. (newer than 30 seconds)
  *
+ *  - Selecting an unknown series usually raises a QueryError but we do not
+ *    raise this error during re-indexing since the series might be in either
+ *    the old- or new pool. (selecting series during re-indexing has therefore
+ *    the same behavior as a regular expression selection)
+ *
+ *  - Drop server is not allowed while re-indexing.
  */
 #ifndef SIRIDB_REINDEX_H_
 #define SIRIDB_REINDEX_H_
index ac15adb02602e2b43ed976a78238ec96289e9344..4b68337c564bed52247c52f7fc5c3efabf781983 100644 (file)
@@ -1,14 +1,5 @@
 /*
  * replicate.h - Replicate SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 11-07-2016
- *
  */
 #ifndef SIRIDB_REPLICATE_H_
 #define SIRIDB_REPLICATE_H_
index f75b1d862db883f5cc837f0f4afdeb932f4009b5..c708489f8f36f917ac2e805afa669871dc9908c8 100644 (file)
@@ -1,13 +1,19 @@
 /*
- * series.h - Series
+ * series.c - SiriDB Time Series.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
  *
- * changes
- *  - initial version, 29-03-2016
+ * Info siridb->series_mutex:
  *
+ *  Main thread:
+ *      siridb->series_map :    read (no lock)      write (lock)
+ *      series->idx :           read (lock)         write (lock)
+ *
+ *  Other threads:
+ *      siridb->series_map :    read (lock)          write (not allowed)
+ *      series->idx :           read (lock)         write (lock)
+ *
+ *  Note:   One exception to 'not allowed' are the free functions
+ *          since they only run when no other references to the object exist.
  */
 #ifndef SIRIDB_SERIES_H_
 #define SIRIDB_SERIES_H_
index d817823f5e4fae203ffbb312f6ae1e28fb27d5b1..7f61ec0a8c7e3d8222333ac7aa3f5683499f846c 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * server.h - SiriDB Server.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 17-03-2016
- *
+ * server.h - Each SiriDB database has at least one server.
  */
 #ifndef SIRIDB_SERVER_H_
 #define SIRIDB_SERVER_H_
index 43ff5f75f995e671bd410d27fbade89a230eb0fd..1e66d13693462d2765a3443751b0170980c80cd1 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * servers.h - SiriDB Servers.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-06-2016
- *
+ * servers.h - Collection of SiriDB servers.
  */
 #ifndef SIRIDB_SERVERS_H_
 #define SIRIDB_SERVERS_H_
@@ -25,7 +17,7 @@ siridb_server_t * siridb_servers_by_replica(
         siridb_server_t * replica);
 
 void siridb_servers_send_pkg(
-        slist_t * servers,
+        vec_t * servers,
         sirinet_pkg_t * pkg,
         uint64_t timeout,
         sirinet_promises_cb cb,
@@ -38,6 +30,6 @@ int siridb_servers_list(siridb_server_t * server, uv_async_t * handle);
 int siridb_servers_check_version(siridb_t * siridb, char * version);
 int siridb_servers_save(siridb_t * siridb);
 int siridb_servers_register(siridb_t * siridb, siridb_server_t * server);
-slist_t * siridb_servers_other2slist(siridb_t * siridb);
+vec_t * siridb_servers_other2vec(siridb_t * siridb);
 
 #endif  /* SIRIDB_SERVERS_H_ */
index 470b2cc4b0bb91a08a11f40869645a770d5d6c9a..85bacfa559e6cb24a4a9b8587e26b1d1713b3983 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * shard.h - SiriDB Shard.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-04-2016
- *
+ * shard.h - SiriDB shard file.
  */
 #ifndef SIRIDB_SHARD_H_
 #define SIRIDB_SHARD_H_
index 3b00cf4e4fa22152c7906b9cdedf6b8703adf64a..48b3736e31451f7f422b254fca48d22f46925376 100644 (file)
@@ -1,13 +1,16 @@
 /*
- * shards.h - SiriDB shards.
+ * shards.h - Collection of SiriDB shards.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
+ * Info shards->mutex:
  *
- * changes
- *  - initial version, 04-04-2016
+ *  Main thread:
+ *      siridb->shards :    read (lock)         write (lock)
+
+ *  Other threads:
+ *      siridb->shards :    read (lock)         write (lock)
  *
+ *  Note: since series->idx hold a reference to a shard, a lock to the
+ *        series_mutex is required in some cases.
  */
 #ifndef SIRIDB_SHARDS_H_
 #define SIRIDB_SHARDS_H_
index 52f0bb5c295ca291d23f2262b5decdaabe75fffc..9e77cdc5b26cc8d05f3a135f71aad89dd2fea8a9 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * tasks.h - SiriDB Error.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 31-10-2016
- *
+ * tasks.f - Counters for info on SiriDB tasks.
  */
 #ifndef SIRIDB_TASKS_H_
 #define SIRIDB_TASKS_H_
index 3488b38902b8333adc2574e63b74515d5aabf31e..151bd021d51da6bbfabd19d5dce75dadb2c45272 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * time.h - Time- and time precision functions and constants.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 09-03-2016
- *
  */
 #ifndef SIRIDB_TIME_H_
 #define SIRIDB_TIME_H_
index 97ef59e46df819c5dc7ff27fe0c8c81210d253a1..d333d732cf539ad86f9bfe15a874b75a9df1fd66 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * user.h - contains functions for a SiriDB database member.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * user.h - Contains functions for a SiriDB database user.
  */
 #ifndef SIRIDB_USER_H_
 #define SIRIDB_USER_H_
index c48d2b15f9b7c16920752e1ecd30cae502910f4d..db1a958f7b82d483637f13bc49fcefbad7c2d746 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * users.h - contains functions for a SiriDB database members.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-05-2016
- *
+ * users.h - Collection of database users.
  */
 #ifndef SIRIDB_USERS_H_
 #define SIRIDB_USERS_H_
index 2fa3058632ae21b1c0b5696f5e663640eaf09108..a5cfbf14759002e73493ec94992b59f7fbcae9ab 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * variance.h - Calculate variance for points.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-08-2016
- *
  */
 #ifndef SIRIDB_VARIANCE_H_
 #define SIRIDB_VARIANCE_H_
index d98dd1c049e45ddb70b9cdb08ef24f03f5e15354..fd9d48af7038c0514dce10d1f7fbc7e8c6430a8b 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * walker.h - creates enter and exit nodes
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-06-2016
- *
+ * walker.h - Creates enter and exit nodes.
  */
 #ifndef SIRIDB_WALKER_H_
 #define SIRIDB_WALKER_H_
index 4daf08564150421e2d725360d3330bbd597e6d7c..12fa6317a62a8630a8b148b8ac820dbf592830cc 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * error.h - SiriDB Error.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 30-06-2016
- *
+ * err.h - SiriDB Error.
  */
 #ifndef SIRI_ERR_H_
 #define SIRI_ERR_H_
index 9da5aa3562ed2b9544022133d6b2f62599d381d7..19d813dd30591acc80f2846be15a4c358f27cf85 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * filehandler.h - Filehandler for shard files.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-04-2016
- *
+ * handler.h - File handler for shard files.
  */
 #ifndef SIRI_FH_H_
 #define SIRI_FH_H_
index 9f53990221f6e5bdf08c5f9c25905006e21f07c0..482de608be074ddef95c8feadcd440a555b2ffeb 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * filepointer.h - File-pointer used in combination with file-handler.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-04-2016
- *
+ * pointer.h - File pointer used in combination with file handler.
  */
 #ifndef SIRI_FP_H_
 #define SIRI_FP_H_
index 0b0137809e5f69e8bf465bdd594d819086196d8f..931fb0b44bd14646c00a89e9511b4990e2311851 100644 (file)
@@ -1,18 +1,11 @@
 /*
  * gramp.h - SiriDB Grammar Properties.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
  * Note: we need this file up-to-date with the grammar. The grammar has
  *       keywords starting with K_ so the will all be sorted.
  *       KW_OFFSET should be set to the first keyword and KW_COUNT needs the
  *       last keyword in the grammar.
  *
- * changes
- *  - initial version, 15-04-2016
- *
  */
 #ifndef SIRI_GRAMP_H_
 #define SIRI_GRAMP_H_
index 35e2b673e511cec6e23a727badd0d0a50b02af2e..50aa27adaf6bacd994b3907b67cfd646379574e2 100644 (file)
@@ -1,17 +1,9 @@
 /*
  * heartbeat.h - Heart-beat task SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
  * There is one and only one heart-beat task thread running for SiriDB. For
  * this reason we do not need to parse data but we should only take care for
  * locks while writing data.
- *
- * changes
- *  - initial version, 17-06-2016
- *
  */
 #ifndef SIRI_HEARTBEAT_H_
 #define SIRI_HEARTBEAT_H_
index e177df65b16e809942032bfee3e2b0548b813531..db5ce6826c52964dc3e5f0d86a1f4ba80695fb1f 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * help.h - Help for SiriDB
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 23-09-2016
- *
+ * help.h - Help for SiriDB.
  */
 #ifndef SIRI_HELP_H_
 #define SIRI_HELP_H_
index 0518598204627042fec59bb689e23bc75192a2d6..affdfe8942fe47f183321beb89cdc6ca7f0bba6b 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * bserver.h - Back-end Server SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 18-06-2016
- *
+ * bserver.h - Listen to back-end SiriDB Server.
  */
 #ifndef SIRINET_BSERVER_H_
 #define SIRINET_BSERVER_H_
index 8381d74e890224ff0c9cda85ff33951d9f36047e..3c0ce0252e8f3e6d7b940b9697c81ead3facb33f 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * clserver.h - TCP server for serving client requests.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 09-03-2016
- *
+ * clserver.h - Listen for client requests.
  */
 #ifndef SIRINET_CLSERVER_H_
 #define SIRINET_CLSERVER_H_
index 51bc7de6e3290092460b38dc8a7f7160587e6d00..076de2277c6ec3bec4ce7c8143cace8f047b4d23 100644 (file)
@@ -1,3 +1,6 @@
+/*
+ * pipe.h - Named Pipe support.
+ */
 #ifndef SIRINET_PIPE_H_
 #define SIRINET_PIPE_H_
 
index 633afd3130593f3a6181ea0ddd64cacb92d1268a..26922b653e380d1dc4fbcf2d76938883e671bd23 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * pkg.h - SiriDB Package type.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-06-2016
- *
  */
 #ifndef SIRINET_PKG_H_
 #define SIRINET_PKG_H_
index 79049c83c196b4afada823bc8598cb9d415772e5..61f7e0575832664eb413d23ead6bbb585126fc5c 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * promise.h - Promise SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 21-06-2016
- *
+ * promise.c - Promise used for sending to data to SiriDB servers.
  */
 #ifndef SIRINET_PROMISE_H_
 #define SIRINET_PROMISE_H_
index 68387023096c85af43b288edcb34dff6d57dcfc6..e653b1dc25881c3d31a917a6707ce90e3be67659 100644 (file)
@@ -1,23 +1,14 @@
 /*
- * promises.h - Promises SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 13-07-2016
- *
+ * promises.h - Collection for promised.
  */
 #ifndef SIRINET_PROMISES_H_
 #define SIRINET_PROMISES_H_
 
 typedef struct sirinet_promises_s sirinet_promises_t;
 
-#include <slist/slist.h>
+#include <vec/vec.h>
 typedef void (* sirinet_promises_cb)(
-        slist_t * promises,
+        vec_t * promises,
         void * data);
 
 #include <siri/net/promise.h>
@@ -28,7 +19,7 @@ sirinet_promises_t * sirinet_promises_new(
         sirinet_promises_cb cb,
         void * data,
         sirinet_pkg_t * pkg);
-void sirinet_promises_llist_free(slist_t * promises);
+void sirinet_promises_llist_free(vec_t * promises);
 void sirinet_promises_on_response(
         sirinet_promise_t * promise,
         sirinet_pkg_t * pkg,
@@ -39,14 +30,14 @@ if (promises->promises->len == promises->promises->size)    \
 {                                                           \
     free(promises->pkg);                                    \
     promises->cb(promises->promises, promises->data);       \
-    slist_free(promises->promises);                         \
+    vec_free(promises->promises);                         \
     free(promises);                                         \
 }
 
 struct sirinet_promises_s
 {
     sirinet_promises_cb cb;
-    slist_t * promises;
+    vec_t * promises;
     void * data;
     sirinet_pkg_t * pkg;
 };
index c8b28fc4d89248ee2562e25fa3ac763ad7944c1c..682e5c3015d4c7f937cfd5f06b4b3be7484a140c 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * protocol.h - Protocol for SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 17-03-2016
- *
+ * protocol.c - Protocol definitions for SiriDB.
  */
 #ifndef SIRINET_PROTOCOL_H_
 #define SIRINET_PROTOCOL_H_
@@ -27,8 +19,8 @@ typedef enum
     CPROTO_REQ_FILE_GROUPS=9,           /* empty                            */
     CPROTO_REQ_FILE_DATABASE=10,        /* empty                            */
 
-    /* Public Administrative API request */
-    CPROTO_REQ_ADMIN=32,                /* (user, password, request, {...}) */
+    /* Public Service API request */
+    CPROTO_REQ_SERVICE=32,              /* (user, password, request, {...}) */
 } cproto_client_t;
 
 typedef enum
@@ -40,9 +32,9 @@ typedef enum
     CPROTO_RES_ACK=3,                   /* empty                            */
     CPROTO_RES_FILE=5,                  /* file content                     */
 
-    /* Administrative API success */
-    CPROTO_ACK_ADMIN=32,                /* empty                            */
-    CPROTO_ACK_ADMIN_DATA=33,           /* [...]                            */
+    /* Service API success */
+    CPROTO_ACK_SERVICE=32,                /* empty                          */
+    CPROTO_ACK_SERVICE_DATA=33,           /* [...]                          */
 
     /* errors 64-69 are errors with messages */
     CPROTO_ERR_MSG=64,                  /* {"error_msg": ...}               */
@@ -57,9 +49,9 @@ typedef enum
     CPROTO_ERR_AUTH_UNKNOWN_DB=73,      /* empty                            */
     CPROTO_ERR_FILE=75,                 /* empty                            */
 
-    /* Administrative API errors */
-    CPROTO_ERR_ADMIN=96,                /* {"error_msg": ...}               */
-    CPROTO_ERR_ADMIN_INVALID_REQUEST=97,/* empty                            */
+    /* Service API errors */
+    CPROTO_ERR_SERVICE=96,                /* {"error_msg": ...}             */
+    CPROTO_ERR_SERVICE_INVALID_REQUEST=97,/* empty                          */
     CPROTO_DEFERRED=127                 /* deferred...                      */
 } cproto_server_t;
 
index 665141b59ad69eace88be77bef238f2c74176c77..48afb3d37372b513bc1f4c5a7b419077322c8ded 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * stream.h - Streams, used for uv_tcp_t and uv_pipe_t.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2018, Transceptor Technology
- *
- * changes
- *  - initial version, 22-08-2018
- *
+ * stream.h - For handling streams.
  */
 #ifndef SIRINET_STREAM_H_
 #define SIRINET_STREAM_H_
index 9430a9bafb17b445f5133080602d6c1cbd7d965f..4612c9734e657662f4d3e87e061554ba6dc954c5 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * tcp.h
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2018, Transceptor Technology
- *
- * changes
- *  - initial version, 22-08-2018
- *
+ * tcp.h - TCP support.
  */
 #ifndef SIRINET_TCP_H_
 #define SIRINET_TCP_H_
index 4e1b39e98207c4b225646251a4a16b5aead03387..52724692ef06d31175e6e27149a7e6226ea574b7 100644 (file)
@@ -1,12 +1,12 @@
 /*
  * optimize.h - Optimize task SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
+ * There is one and only one optimize task thread running for SiriDB. For this
+ * reason we do not need to parse data but we should only take care for locks
+ * while writing data.
  *
- * changes
- *  - initial version, 09-05-2016
+ * Thread debugging:
+ *  log_debug("getpid: %d - pthread_self: %lu",getpid(), pthread_self());
  *
  */
 #ifndef SIRI_OPTIMIZE_H_
diff --git a/include/siri/service/account.h b/include/siri/service/account.h
new file mode 100644 (file)
index 0000000..1de94bf
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * account.h - SiriDB Service Account.
+ */
+#ifndef SIRI_SERVICE_ACCOUNT_H_
+#define SIRI_SERVICE_ACCOUNT_H_
+
+typedef struct siri_service_account_s siri_service_account_t;
+
+#include <qpack/qpack.h>
+#include <siri/siri.h>
+
+int siri_service_account_init(siri_t * siri);
+void siri_service_account_destroy(siri_t * siri);
+int siri_service_account_new(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        qp_obj_t * qp_password,
+        int is_encrypted,
+        char * err_msg);
+int siri_service_account_check(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        qp_obj_t * qp_password,
+        char * err_msg);
+int siri_service_account_change_password(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        qp_obj_t * qp_password,
+        char * err_msg);
+int siri_service_account_drop(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        char * err_msg);
+int siri_service_account_save(siri_t * siri, char * err_msg);
+
+struct siri_service_account_s
+{
+    char * account;
+    char * password; /* keeps an encrypted password */
+};
+
+#endif  /* SIRI_SERVICE_ACCOUNT_H_ */
diff --git a/include/siri/service/client.h b/include/siri/service/client.h
new file mode 100644 (file)
index 0000000..93c390d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * client.h - Client for expanding a SiriDB database.
+ */
+#ifndef SIRI_SERVICE_CLIENT_H_
+#define SIRI_SERVICE_CLIENT_H_
+
+typedef struct siri_service_client_s siri_service_client_t;
+
+#include <inttypes.h>
+#include <uv.h>
+#include <qpack/qpack.h>
+#include <uuid/uuid.h>
+#include <siri/net/pkg.h>
+
+int siri_service_client_request(
+        uint16_t pid,
+        uint16_t port,
+        int pool,
+        uuid_t * uuid,
+        qp_obj_t * host,
+        qp_obj_t * username,
+        qp_obj_t * password,
+        qp_obj_t * dbname,
+        const char * dbpath,
+        sirinet_stream_t * client,
+        char * err_msg);
+
+void siri_service_client_free(siri_service_client_t * adm_client);
+
+struct siri_service_client_s
+{
+    uint8_t request;
+    uint8_t flags;
+    uint16_t pid;
+    uint16_t port;
+    uuid_t uuid;
+    int pool;  /*       -1 for a new pool       */
+    char * host;
+    char * username;
+    char * password;
+    char * dbname;
+    char * dbpath;
+    sirinet_stream_t * client;
+    sirinet_pkg_t * pkg;
+};
+
+#endif  /* SIRI_SERVICE_CLIENT_H_ */
diff --git a/include/siri/service/request.h b/include/siri/service/request.h
new file mode 100644 (file)
index 0000000..afececf
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * request.h - SiriDB Service Request.
+ */
+#ifndef SIRI_SERVICE_REQUEST_H_
+#define SIRI_SERVICE_REQUEST_H_
+
+typedef enum
+{
+    SERVICE_NEW_ACCOUNT_,
+    SERVICE_CHANGE_PASSWORD_,
+    SERVICE_DROP_ACCOUNT_,
+    SERVICE_NEW_DATABASE_,
+    SERVICE_NEW_POOL,
+    SERVICE_NEW_REPLICA,
+    SERVICE_GET_VERSION=64,
+    SERVICE_GET_ACCOUNTS,
+    SERVICE_GET_DATABASES
+} service_request_t;
+
+#include <qpack/qpack.h>
+#include <siri/net/protocol.h>
+
+int siri_service_request_init(void);
+void siri_service_request_destroy(void);
+cproto_server_t siri_service_request(
+        int tp,
+        qp_unpacker_t * qp_unpacker,
+        qp_obj_t * qp_account,
+        qp_packer_t ** packaddr,
+        uint16_t pid,
+        sirinet_stream_t * client,
+        char * err_msg);
+void siri_service_request_rollback(const char * dbpath);
+
+
+#endif  /* SIRI_SERVICE_REQUEST_H_ */
index 9f947d1cd015c8e5c495dc96d0bde7f5c45badd0..add8a439dcf098b7b29501cd7303b45328911856 100644 (file)
@@ -1,12 +1,14 @@
 /*
- * siri.h - global methods for SiriDB.
+ * siri.h - Root for SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
  *
- * changes
- *  - initial version, 08-03-2016
+ * Info siri->siridb_mutex:
+ *
+ *  Main thread:
+ *      siri->siridb_list :    read (no lock)          write (lock)
+ *
+ *  Other threads:
+ *      siri->siridb_list :    read (lock)          write (not allowed)
  *
  */
 #ifndef SIRI_H_
@@ -61,10 +63,10 @@ struct siri_s
     uv_mutex_t siridb_mutex;
     uint32_t startup_time;
 
-    /* initialized by sidi_admin_account_init */
+    /* initialized by sidi_service_account_init */
     llist_t * accounts;
 
-    /* initialized by sidi_admin_request_init */
+    /* initialized by sidi_service_request_init */
     pcre2_code * dbname_regex;
     pcre2_match_data * dbname_match_data;
 
index 3967a0fda417b837a46aa07aa81947db60b78c3e..5cf74a818b04635374b03a8f2103020615bb5ca6 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * version.h - contains SiriDB version info.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * version.h - SiriDB version info.
  */
 #ifndef SIRI_VERSION_H_
 #define SIRI_VERSION_H_
diff --git a/include/slist/slist.h b/include/slist/slist.h
deleted file mode 100644 (file)
index 42915e8..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * slist.h - Simple List
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 06-06-2016
- *
- */
-#ifndef SLIST_H_
-#define SLIST_H_
-
-#define SLIST_DEFAULT_SIZE 8
-
-typedef struct slist_s slist_t;
-typedef struct slist_object_s slist_object_t;
-
-#include <stdio.h>
-#include <stddef.h>
-#include <inttypes.h>
-
-slist_t * slist_new(size_t size);
-slist_t * slist_copy(slist_t * source);
-void slist_compact(slist_t ** slist);
-int slist_append_safe(slist_t ** slist, void * data);
-
-/*
- * Expects the object to have a object->ref (uint_xxx_t) on top of the
- * objects definition.
- */
-#define slist_object_incref(object) ((slist_object_t * ) object)->ref++
-
-/*
- * Expects the object to have a object->ref (uint_xxx_t) on top of the
- * objects definition.
- *
- * WARNING: Be careful using 'slist_object_decref' only when being sure
- *          there are still references left on the object since an object
- *          probably needs specific cleanup tasks.
- */
-#define slist_object_decref(object) ((slist_object_t * ) object)->ref--
-
-/*
- * Append data to the list. This functions assumes the list can hold the new
- * data is therefore not safe.
- */
-#define slist_append(slist, _data) slist->data[slist->len++] = _data
-
-/*
- * Destroy the simple list.
- */
-#define slist_free(slist) free(slist)
-
-/*
- * Pop the last item from the list
- */
-#define slist_pop(slist) slist->data[--slist->len]
-
-struct slist_object_s
-{
-    uint32_t ref;
-};
-
-struct slist_s
-{
-    size_t size;
-    size_t len;
-    void * data[];
-};
-
-#endif  /* SLIST_H_ */
diff --git a/include/strextra/strextra.h b/include/strextra/strextra.h
deleted file mode 100644 (file)
index 617155d..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * strextra.h - Extra String functions used by SiriDB
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 19-03-2016
- *
- */
-#ifndef STREXTRA_H_
-#define STREXTRA_H_
-
-#include <stdbool.h>
-#include <stddef.h>
-#include <inttypes.h>
-
-void strx_upper_case(char * sptr);
-void strx_lower_case(char * sptr);
-void strx_replace_char(char * sptr, char orig, char repl);
-int strx_replace_str(char * str, char * o, char * r, size_t n);
-void strx_split_join(char * pt, char split_chr, char join_chr);
-
-/* do not use trim when the char is created with *alloc */
-void strx_trim(char ** str, char chr);
-bool strx_is_empty(const char * str);
-bool strx_is_int(const char * str);
-bool strx_is_float(const char * str);
-bool strx_is_graph(const char * str);
-double strx_to_double(const char * src, size_t len);
-uint64_t strx_to_uint64(const char * src, size_t len);
-char * strx_dup(const char * src, size_t * n);
-
-/* important: 'dest' needs to be freed */
-size_t strx_extract_string(char * dest, const char * source, size_t len);
-
-#endif  /* STREXTRA_H_ */
index 3d95c91f18977fa3b80898da0e281d51b6686d71..d7d4038ef0df5fd4b16318a20e35ae0d2528c296 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * timeit.h - Timeit.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2016
- *
  */
 #ifndef TIMEIT_H_
 #define TIMEIT_H_
diff --git a/include/vec/vec.h b/include/vec/vec.h
new file mode 100644 (file)
index 0000000..9600bea
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * vec.h - Vector List.
+ */
+#ifndef VEC_H_
+#define VEC_H_
+
+#define VEC_DEFAULT_SIZE 8
+
+typedef struct vec_s vec_t;
+typedef struct vec_object_s vec_object_t;
+
+#include <stdio.h>
+#include <stddef.h>
+#include <inttypes.h>
+
+vec_t * vec_new(size_t size);
+vec_t * vec_copy(vec_t * source);
+void vec_compact(vec_t ** vec);
+int vec_append_safe(vec_t ** vec, void * data);
+
+/*
+ * Expects the object to have a object->ref (uint_xxx_t) on top of the
+ * objects definition.
+ */
+#define vec_object_incref(object) ((vec_object_t * ) object)->ref++
+
+/*
+ * Expects the object to have a object->ref (uint_xxx_t) on top of the
+ * objects definition.
+ *
+ * WARNING: Be careful using 'vec_object_decref' only when being sure
+ *          there are still references left on the object since an object
+ *          probably needs specific cleanup tasks.
+ */
+#define vec_object_decref(object) ((vec_object_t * ) object)->ref--
+
+/*
+ * Append data to the list. This functions assumes the list can hold the new
+ * data is therefore not safe.
+ */
+#define vec_append(vec, _data) vec->data[vec->len++] = _data
+
+/*
+ * Destroy the vector.
+ */
+#define vec_free(vec) free(vec)
+
+/*
+ * Pop the last item from the list
+ */
+#define vec_pop(vec) vec->data[--vec->len]
+
+struct vec_object_s
+{
+    uint32_t ref;
+};
+
+struct vec_s
+{
+    size_t size;
+    size_t len;
+    void * data[];
+};
+
+#endif  /* VEC_H_ */
index 9f16df223f6496d12a8b7676f244b8eead35f529..80b9fda375e5700695b4b0c8ffadf232fb0072c2 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * xmath.h - Extra math functions which are useful.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 12-03-2016
- *
+ * xmath.h - Extra math functions functions used by SiriDB.
  */
 #ifndef XMATH_H_
 #define XMATH_H_
index c2141fd840750ddd956d139d617b229f90234a36..9524ef99606f420f8c484d7672c787a2495c9617 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * xpath.h - Path and file tools
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 15-07-2016
- *
+ * xpath.h - Path and file tools.
  */
 #ifndef XPATH_H_
 #define XPATH_H_
diff --git a/include/xstr/xstr.h b/include/xstr/xstr.h
new file mode 100644 (file)
index 0000000..30d1212
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * xstr.h - Extra String functions used by SiriDB.
+ */
+#ifndef XSTR_H_
+#define XSTR_H_
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <inttypes.h>
+
+void xstr_upper_case(char * sptr);
+void xstr_lower_case(char * sptr);
+void xstr_replace_char(char * sptr, char orig, char repl);
+int xstr_replace_str(char * str, char * o, char * r, size_t n);
+void xstr_split_join(char * pt, char split_chr, char join_chr);
+
+/* do not use trim when the char is created with *alloc */
+void xstr_trim(char ** str, char chr);
+bool xstr_is_empty(const char * str);
+bool xstr_is_int(const char * str);
+bool xstr_is_float(const char * str);
+bool xstr_is_graph(const char * str);
+double xstr_to_double(const char * src, size_t len);
+uint64_t xstr_to_uint64(const char * src, size_t len);
+char * xstr_dup(const char * src, size_t * n);
+
+/* important: 'dest' needs to be freed */
+size_t xstr_extract_string(char * dest, const char * source, size_t len);
+
+#endif  /* XSTR_H_ */
index 005b24b18f7e7a23f626ef1e4ebc20e92f9f714a..1cbcbd6d93af69415075f002be9ddc2cb985e7a4 100644 (file)
@@ -20,8 +20,8 @@ RUN apt-get update && \
         valgrind \
         libuv1 \
         libpcre2-8-0 && \
-    wget https://github.com/SiriDB/siridb-admin/releases/download/1.1.3/siridb-admin_1.1.3_linux_amd64.bin -O /usr/local/bin/siridb-admin && \
-    chmod +x /usr/local/bin/siridb-admin
+    wget https://github.com/SiriDB/siridb-service/releases/download/1.1.3/siridb-service_1.1.3_linux_amd64.bin -O /usr/local/bin/siridb-service && \
+    chmod +x /usr/local/bin/siridb-service
 COPY --from=builder ./Release/siridb-server /Release/siridb-server
 COPY --from=builder /usr/lib/x86_64-linux-gnu/libcleri* /usr/lib/x86_64-linux-gnu/
 COPY ./itest/ /itest/
index b4a59329aa2a47bbfeca8c59b49577380e5ae58a..8e91bea96d620f8dffcb4a152051a7447fcc0cc9 100644 (file)
@@ -1,6 +1,6 @@
 TEST_DIR = './testdir'
 SIRIDBC = '../{BUILDTYPE}/siridb-server'
-ADMIN = '/usr/local/bin/siridb-admin'
+SERVICE = '/usr/local/bin/siridb-service'
 VALGRIND = 'valgrind' \
   ' --tool=memcheck' \
   ' --error-exitcode=1' \
index 077c3a5f7c833521693a33428d13bb18e34c2fe5..71e7b8f21612e3847a6bf8cb58bce62ecc94dda3 100644 (file)
@@ -2,7 +2,7 @@ import os
 import logging
 import random
 import asyncio
-from .constants import ADMIN
+from .constants import SERVICE
 
 VERBOSE = ' --verbose'
 
@@ -35,7 +35,7 @@ class SiriDB:
             server.name))
 
         rc = os.system(
-            '{admin} '
+            '{service} '
             '-u sa -p siri -s {addr} '
             'new-database '
             '--db-name {dbname} '
@@ -44,7 +44,7 @@ class SiriDB:
             '--duration-num {duration_num} '
             '--buffer-size {buffer_size}'
             '{verbose}'.format(
-                admin=ADMIN,
+                service=SERVICE,
                 addr=server.addr,
                 verbose=VERBOSE if self.LOG_LEVEL == 'DEBUG'
                 else ' >/dev/null',
@@ -70,7 +70,7 @@ class SiriDB:
             remote_server = random.choice(self.servers)
 
         rc = os.system(
-            '{admin} '
+            '{service} '
             '-u sa -p siri -s {addr} '
             'new-replica '
             '--db-name {dbname} '
@@ -79,7 +79,7 @@ class SiriDB:
             '--db-password {dbpassword} '
             '--pool {pool} '
             '--force{verbose}'.format(
-                admin=ADMIN,
+                service=SERVICE,
                 addr=server.addr,
                 dbaddr=remote_server.addr,
                 dbuser=username,
@@ -108,7 +108,7 @@ class SiriDB:
             remote_server = random.choice(self.servers)
 
         rc = os.system(
-            '{admin} '
+            '{service} '
             '-u sa -p siri -s {addr} '
             'new-pool '
             '--db-name {dbname} '
@@ -116,7 +116,7 @@ class SiriDB:
             '--db-user {dbuser} '
             '--db-password {dbpassword} '
             '--force{verbose}'.format(
-                admin=ADMIN,
+                service=SERVICE,
                 addr=server.addr,
                 dbaddr=remote_server.addr,
                 dbuser=username,
diff --git a/main.c b/main.c
index 4e9940f2e8887e09ed0464bc9629e09e9ca849b1..085004dbd07376bf12d45e26cca67c26d10a62b1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,12 +1,10 @@
 /*
  * main.c - SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
+ * author/maintainer : Jeroen van der Heijden <jeroen@transceptor.technology>
+ * contributors      : https://github.com/SiriDB/siridb-server/contributors
+ * home page         : https://siridb.net
+ * copyright         : 2018, Transceptor Technology
  *
  */
 #include <locale.h>
index 3b4657d0fe7b2d98de18b35c028e18e1c9e6d766..d5a722681569c31ee8d15148ea48684d08a2a7f9 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * argparse.c - module for parsing command line arguments.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * argparse.c - Module for parsing command line arguments.
  */
 #include <argparse/argparse.h>
 #include <libgen.h>
@@ -15,7 +7,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 #include <assert.h>
 
@@ -243,8 +235,8 @@ static void print_usage(argparse_parser_t * parser, const char * bname)
         case ARGPARSE_STORE_STRING:
         case ARGPARSE_STORE_INT:
             strcpy(uname, current->argument->name);
-            strx_replace_char(uname, '-', '_');
-            strx_upper_case(uname);
+            xstr_replace_char(uname, '-', '_');
+            xstr_upper_case(uname);
             if (current->argument->shortcut)
                 snprintf(buffer, ARGPARSE_HELP_SIZE,
                         "[-%c %s] ",
@@ -312,8 +304,8 @@ static void print_help(argparse_parser_t * parser, const char * bname)
         case ARGPARSE_STORE_STRING:
         case ARGPARSE_STORE_INT:
             strcpy(uname, current->argument->name);
-            strx_replace_char(uname, '-', '_');
-            strx_upper_case(uname);
+            xstr_replace_char(uname, '-', '_');
+            xstr_upper_case(uname);
             if (current->argument->shortcut)
                 snprintf(buffer, ARGPARSE_HELP_SIZE,
                         " -%c %s,",
index 517bb57ef3e654952e89735483b96f001c03296a..6bd01fd1a07b9d1edffea92dd6a2689155724d4e 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * cexpr.c - Conditional expressions.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-06-2016
- *
  */
 #include <cexpr/cexpr.h>
 #include <assert.h>
@@ -18,7 +10,7 @@
 #include <siri/db/series.h>
 #include <siri/db/shard.h>
 #include <siri/db/access.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 
 #define VIA_NULL 0
 #define VIA_CEXPR 1
@@ -402,7 +394,7 @@ static cexpr_t * CEXPR_walk_node(
                 {
                     return NULL;
                 }
-                strx_extract_string((*condition)->str, node->str, node->len);
+                xstr_extract_string((*condition)->str, node->str, node->len);
                 SET_CONDITION_AND_RETURN
             }
             /* can be a choice between keywords, in that case just wait */
index db8920e9f290c91a338aafa5b31101cf564f3da0..c1e00e3de34412f3a23f9338236d3009ac3311d4 100644 (file)
@@ -1,20 +1,12 @@
 /*
- * cfgparser.c - module for reading (and later writing) to INI style files.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * cfgparser.c - Reading (and later writing) to INI style files.
  */
 #include <cfgparser/cfgparser.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <siri/err.h>
 
 static void cfgparser_free_sections(cfgparser_section_t * root);
@@ -60,7 +52,7 @@ cfgparser_return_t cfgparser_read(cfgparser_t * cfgparser, const char * fn)
         pt = line;
 
         /* trims all whitespace */
-        strx_trim(&pt, 0);
+        xstr_trim(&pt, 0);
 
         if (*pt == '#' || *pt == 0)
         {
@@ -69,8 +61,8 @@ cfgparser_return_t cfgparser_read(cfgparser_t * cfgparser, const char * fn)
 
         if (*pt == '[' && pt[strlen(pt) - 1] == ']')
         {
-            strx_trim(&pt, '[');
-            strx_trim(&pt, ']');
+            xstr_trim(&pt, '[');
+            xstr_trim(&pt, ']');
             section = cfgparser_section(cfgparser, pt);
             if (section == NULL)
             {
@@ -111,11 +103,11 @@ cfgparser_return_t cfgparser_read(cfgparser_t * cfgparser, const char * fn)
         }
 
 
-        if (strx_is_int(pt))
+        if (xstr_is_int(pt))
         {
             option = cfgparser_integer_option(section, name, atoi(pt), 0);
         }
-        else if (strx_is_float(pt))
+        else if (xstr_is_float(pt))
         {
             sscanf(pt, "%lf", &d);
             option = cfgparser_real_option(section, name, d, 0.0f);
index 4d84a619ce73cbe602f27433652b1c0c03531c69..0693a6145e2793d370fc2f9e7ed7aeb2cf4b4fcc 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * ctree.c - Compact Binary Tree implementation.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-03-2016
- *
  */
 #include <ctree/ctree.h>
 #include <stdio.h>
index b7c40a631962e8f7b033327e505f5b615c4277c5..c3b6ff641488f3f3ab373b635c32eb8a1ac9baaf 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * expr.c - Parse expression
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 19-04-2016
- *
+ * expr.c - For parsing expressions.
  */
 #include <stdio.h>
 #include <ctype.h>
index 30739c251b5055c4dc49cf53603fce0f7ab91fad..dac1eaf646e227320d538efe95f59791d923e1b4 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * imap.c - map for uint64_t integer keys
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 03-08-2016
- *
+ * imap.c - Lookup map for uint64_t integer keys with set operation support.
  */
 #include <assert.h>
 #include <imap/imap.h>
@@ -24,8 +16,8 @@ static int IMAP_add(imap_node_t * node, uint64_t id, void * data);
 static void * IMAP_pop(imap_node_t * node, uint64_t id);
 static void IMAP_walk(imap_node_t * node, imap_cb cb, void * data, int * rc);
 static void IMAP_walkn(imap_node_t * node, imap_cb cb, void * data, size_t * n);
-static void IMAP_2slist(imap_node_t * node, slist_t * slist);
-static void IMAP_2slist_ref(imap_node_t * node, slist_t * slist);
+static void IMAP_2vec(imap_node_t * node, vec_t * vec);
+static void IMAP_2vec_ref(imap_node_t * node, vec_t * vec);
 static void IMAP_union_ref(imap_node_t * dest, imap_node_t * node);
 static void IMAP_intersection_ref(
         imap_node_t * dest,
@@ -54,7 +46,7 @@ imap_t * imap_new(void)
     }
 
     imap->len = 0;
-    imap->slist = NULL;
+    imap->vec = NULL;
 
     return imap;
 }
@@ -100,7 +92,7 @@ void imap_free(imap_t * imap, imap_free_cb cb)
         }
     }
 
-    slist_free(imap->slist);
+    vec_free(imap->vec);
     free(imap);
 }
 
@@ -138,11 +130,11 @@ int imap_set(imap_t * imap, uint64_t id, void * data)
         }
     }
 
-    if (imap->slist != NULL && (
-            rc < 1 || slist_append_safe(&imap->slist, data)))
+    if (imap->vec != NULL && (
+            rc < 1 || vec_append_safe(&imap->vec, data)))
     {
-        slist_free(imap->slist);
-        imap->slist = NULL;
+        vec_free(imap->vec);
+        imap->vec = NULL;
     }
 
     return rc;
@@ -184,10 +176,10 @@ int imap_add(imap_t * imap, uint64_t id, void * data)
         imap->len++;
     }
 
-    if (imap->slist != NULL && slist_append_safe(&imap->slist, data))
+    if (imap->vec != NULL && vec_append_safe(&imap->vec, data))
     {
-        slist_free(imap->slist);
-        imap->slist = NULL;
+        vec_free(imap->vec);
+        imap->vec = NULL;
     }
 
     return 0;
@@ -232,10 +224,10 @@ void * imap_pop(imap_t * imap, uint64_t id)
     {
         imap->len--;
 
-        if (imap->slist != NULL)
+        if (imap->vec != NULL)
         {
-            slist_free(imap->slist);
-            imap->slist = NULL;
+            vec_free(imap->vec);
+            imap->vec = NULL;
         }
     }
 
@@ -309,15 +301,15 @@ void imap_walkn(imap_t * imap, size_t * n, imap_cb cb, void * data)
 /*
  * Returns NULL in case an error has occurred.
  *
- * When successful a BORROWED pointer to slist is returned.
+ * When successful a BORROWED pointer to vec is returned.
  */
-slist_t * imap_slist(imap_t * imap)
+vec_t * imap_vec(imap_t * imap)
 {
-    if (imap->slist == NULL)
+    if (imap->vec == NULL)
     {
-        imap->slist = slist_new(imap->len);
+        imap->vec = vec_new(imap->len);
 
-        if (imap->slist != NULL && imap->len)
+        if (imap->vec != NULL && imap->len)
         {
             imap_node_t * nd;
             uint_fast8_t i;
@@ -328,47 +320,47 @@ slist_t * imap_slist(imap_t * imap)
 
                 if (nd->data != NULL)
                 {
-                    slist_append(imap->slist, nd->data);
+                    vec_append(imap->vec, nd->data);
                 }
 
                 if (nd->nodes != NULL)
                 {
-                    IMAP_2slist(nd, imap->slist);
+                    IMAP_2vec(nd, imap->vec);
                 }
             }
         }
     }
-    return imap->slist;
+    return imap->vec;
 }
 
 /*
  * Returns NULL in case an error has occurred.
  *
- * When successful a the slist is returned and imap->slist is set to NULL.
+ * When successful a the vec is returned and imap->vec is set to NULL.
  *
  * This can be used when being sure this is the only time you need the list
  * and prevents making a copy.
  */
-slist_t * imap_slist_pop(imap_t * imap)
+vec_t * imap_vec_pop(imap_t * imap)
 {
-    slist_t * slist = imap_slist(imap);
-    imap->slist = NULL;
-    return slist;
+    vec_t * vec = imap_vec(imap);
+    imap->vec = NULL;
+    return vec;
 }
 
 /*
  * Returns NULL in case an error has occurred.
  *
- * When successful a NEW slist is returned.
+ * When successful a NEW vec is returned.
  */
-slist_t * imap_2slist(imap_t * imap)
+vec_t * imap_2vec(imap_t * imap)
 {
-    slist_t * slist = imap_slist(imap);
-    if (slist != NULL)
+    vec_t * vec = imap_vec(imap);
+    if (vec != NULL)
     {
-        slist = slist_copy(slist);
+        vec = vec_copy(vec);
     }
-    return slist;
+    return vec;
 }
 
 /*
@@ -382,13 +374,13 @@ slist_t * imap_2slist(imap_t * imap)
  *
  * Returns NULL in case an error has occurred.
  */
-slist_t * imap_2slist_ref(imap_t * imap)
+vec_t * imap_2vec_ref(imap_t * imap)
 {
-    if (imap->slist == NULL)
+    if (imap->vec == NULL)
     {
-        imap->slist = slist_new(imap->len);
+        imap->vec = vec_new(imap->len);
 
-        if (imap->slist != NULL && imap->len)
+        if (imap->vec != NULL && imap->len)
         {
             imap_node_t * nd;
             uint_fast8_t i;
@@ -399,13 +391,13 @@ slist_t * imap_2slist_ref(imap_t * imap)
 
                 if (nd->data != NULL)
                 {
-                    slist_append(imap->slist, nd->data);
-                    slist_object_incref(nd->data);
+                    vec_append(imap->vec, nd->data);
+                    vec_object_incref(nd->data);
                 }
 
                 if (nd->nodes != NULL)
                 {
-                    IMAP_2slist_ref(nd, imap->slist);
+                    IMAP_2vec_ref(nd, imap->vec);
                 }
             }
         }
@@ -413,13 +405,13 @@ slist_t * imap_2slist_ref(imap_t * imap)
     else
     {
         size_t i;
-        for (i = 0; i < imap->slist->len; i++)
+        for (i = 0; i < imap->vec->len; i++)
         {
-            slist_object_incref(imap->slist->data[i]);
+            vec_object_incref(imap->vec->data[i]);
         }
     }
 
-    return (imap->slist == NULL) ? NULL : slist_copy(imap->slist);
+    return (imap->vec == NULL) ? NULL : vec_copy(imap->vec);
 }
 
 /*
@@ -436,10 +428,10 @@ void imap_union_ref(
         imap_t * imap,
         imap_free_cb decref_cb __attribute__((unused)))
 {
-    if (dest->slist != NULL)
+    if (dest->vec != NULL)
     {
-        slist_free(dest->slist);
-        dest->slist = NULL;
+        vec_free(dest->vec);
+        dest->vec = NULL;
     }
 
     if (imap->len)
@@ -460,7 +452,7 @@ void imap_union_ref(
                     /* this must be the same object */
                     assert (imap_nd->data == dest_nd->data);
                     /* we are sure there is a ref left */
-                    slist_object_decref(imap_nd->data);
+                    vec_object_decref(imap_nd->data);
                 }
                 else
                 {
@@ -488,7 +480,7 @@ void imap_union_ref(
     }
 
     /* cleanup source imap */
-    slist_free(imap->slist);
+    vec_free(imap->vec);
     free(imap);
 }
 
@@ -506,10 +498,10 @@ void imap_intersection_ref(
         imap_t * imap,
         imap_free_cb decref_cb)
 {
-    if (dest->slist != NULL)
+    if (dest->vec != NULL)
     {
-        slist_free(dest->slist);
-        dest->slist = NULL;
+        vec_free(dest->vec);
+        dest->vec = NULL;
     }
 
     imap_node_t * dest_nd;
@@ -553,7 +545,7 @@ void imap_intersection_ref(
     }
 
     /* cleanup source imap */
-    slist_free(imap->slist);
+    vec_free(imap->vec);
     free(imap);
 }
 
@@ -571,10 +563,10 @@ void imap_difference_ref(
         imap_t * imap,
         imap_free_cb decref_cb)
 {
-    if (dest->slist != NULL)
+    if (dest->vec != NULL)
     {
-        slist_free(dest->slist);
-        dest->slist = NULL;
+        vec_free(dest->vec);
+        dest->vec = NULL;
     }
 
     if (imap->len)
@@ -596,7 +588,7 @@ void imap_difference_ref(
                     assert (imap_nd->data == dest_nd->data);
 
                     /* we are sure to have one ref left */
-                    slist_object_decref(dest_nd->data);
+                    vec_object_decref(dest_nd->data);
                     dest_nd->data = NULL;
                     dest->len--;
 
@@ -622,7 +614,7 @@ void imap_difference_ref(
     }
 
     /* cleanup source imap */
-    slist_free(imap->slist);
+    vec_free(imap->vec);
     free(imap);
 }
 
@@ -640,10 +632,10 @@ void imap_symmetric_difference_ref(
         imap_t * imap,
         imap_free_cb decref_cb)
 {
-    if (dest->slist != NULL)
+    if (dest->vec != NULL)
     {
-        slist_free(dest->slist);
-        dest->slist = NULL;
+        vec_free(dest->vec);
+        dest->vec = NULL;
     }
 
     if (imap->len)
@@ -665,7 +657,7 @@ void imap_symmetric_difference_ref(
                     assert (imap_nd->data == dest_nd->data);
 
                     /* we are sure to have one ref left */
-                    slist_object_decref(dest_nd->data);
+                    vec_object_decref(dest_nd->data);
 
                     /* but now we are not sure anymore */
                     (*decref_cb)(imap_nd->data);
@@ -702,7 +694,7 @@ void imap_symmetric_difference_ref(
     }
 
     /* cleanup source imap */
-    slist_free(imap->slist);
+    vec_free(imap->vec);
     free(imap);
 }
 
@@ -915,7 +907,7 @@ static void IMAP_walkn(imap_node_t * node, imap_cb cb, void * data, size_t * n)
     }
 }
 
-static void IMAP_2slist(imap_node_t * node, slist_t * slist)
+static void IMAP_2vec(imap_node_t * node, vec_t * vec)
 {
     imap_node_t * nd;
     uint_fast8_t i;
@@ -926,17 +918,17 @@ static void IMAP_2slist(imap_node_t * node, slist_t * slist)
 
         if (nd->data != NULL)
         {
-            slist_append(slist, nd->data);
+            vec_append(vec, nd->data);
         }
 
         if (nd->nodes != NULL)
         {
-            IMAP_2slist(nd, slist);
+            IMAP_2vec(nd, vec);
         }
     }
 }
 
-static void IMAP_2slist_ref(imap_node_t * node, slist_t * slist)
+static void IMAP_2vec_ref(imap_node_t * node, vec_t * vec)
 {
     imap_node_t * nd;
     uint_fast8_t i;
@@ -947,13 +939,13 @@ static void IMAP_2slist_ref(imap_node_t * node, slist_t * slist)
 
         if (nd->data != NULL)
         {
-            slist_append(slist, nd->data);
-            slist_object_incref(nd->data);
+            vec_append(vec, nd->data);
+            vec_object_incref(nd->data);
         }
 
         if (nd->nodes != NULL)
         {
-            IMAP_2slist_ref(nd, slist);
+            IMAP_2vec_ref(nd, vec);
         }
     }
 }
@@ -976,7 +968,7 @@ static void IMAP_union_ref(imap_node_t * dest, imap_node_t * node)
                 /* this must be the same object */
                 assert (node_nd->data == dest_nd->data);
                 /* we are sure there is a ref left */
-                slist_object_decref(node_nd->data);
+                vec_object_decref(node_nd->data);
             }
             else
             {
@@ -1081,7 +1073,7 @@ static void IMAP_difference_ref(
                 /* this must be the same object */
                 assert (node_nd->data == dest_nd->data);
                 /* we are sure to have one ref left */
-                slist_object_decref(dest_nd->data);
+                vec_object_decref(dest_nd->data);
                 dest_nd->data = NULL;
                 dest->size--;
 
@@ -1136,7 +1128,7 @@ static void IMAP_symmetric_difference_ref(
                 assert (node_nd->data == dest_nd->data);
 
                 /* we are sure to have one ref left */
-                slist_object_decref(dest_nd->data);
+                vec_object_decref(dest_nd->data);
 
                 /* but now we are not sure anymore */
                 (*decref_cb)(node_nd->data);
index dde56710d06c61e62969c78b10a53f287efd5805..7a9b44616e9dfd0899299103f64f896948e3e7ee 100644 (file)
@@ -1,18 +1,6 @@
 /*
- * iso8601.c - Library to parse ISO 8601 dates
- *
- * Note: time-zones are found with tzset() in either /usr/lib/zoneinfo/ or
- *       /usr/share/zoneinfo/
- *
- *       (This library is Linux only)
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 21-04-2016
- *
+ * iso8601.c - Library to parse ISO 8601 dates. Time-zones are found with
+ *             tzset() in either /usr/lib/zoneinfo/ or /usr/share/zoneinfo/.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
index b8b0cff59db82952b252cb642b4dbb47083b048a..290877fea234360443130158e23930df9e7f86de 100644 (file)
@@ -1,15 +1,6 @@
 /*
- * llist.c - Linked List
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 03-05-2016
- *
+ * llist.c - Linked List implementation.
  */
-
 #include <stddef.h>
 #include <stdlib.h>
 #include <llist/llist.h>
@@ -248,11 +239,11 @@ void * llist_get(llist_t * llist, llist_cb cb, void * args)
  * Copy the linked list to a simple list.
  * (returns NULL in case an error has occurred)
  */
-slist_t * llist2slist(llist_t * llist)
+vec_t * llist2vec(llist_t * llist)
 {
-    slist_t * slist = slist_new(llist->len);
+    vec_t * vec = vec_new(llist->len);
 
-    if (slist == NULL)
+    if (vec == NULL)
     {
         return NULL;
     }
@@ -262,12 +253,12 @@ slist_t * llist2slist(llist_t * llist)
 
     for  (n = 0; node != NULL; n++, node = node->next)
     {
-        slist->data[n] = node->data;
+        vec->data[n] = node->data;
     }
 
-    slist->len = n;
+    vec->len = n;
 
-    return slist;
+    return vec;
 }
 
 /*
index 8444e1a4d87a85f06382304e8237bee30b619d37..47a5b75206ea2e854654c38023bb041f3f26993f 100644 (file)
@@ -1,15 +1,5 @@
 /*
- * lock.c - SiriDB Lock.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * This module works only in Linux
- *
- * changes
- *  - initial version, 13-07-2016
- *
+ * lock.c - Lock a directory by using a lock file.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
index e7829e47b6646c9064f6aba911f14506da140c3f..6cad93508283753fa5ae1e71c42ff1a98d15e7a6 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * logger.c - log module
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * logger.h - Logging module.
  */
 #include <logger/logger.h>
 #include <stdio.h>
index 3d120991f797e372d0fba9f3634951aa951cffbb..9157328a9dd44bc0faf546f7af88eaa958c9030c 100644 (file)
@@ -1,13 +1,6 @@
 /*
  * owcrypt.c - One Way Encryption. (used for storing a database user password)
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes:
- *  - initial version, 24-02-2017
- *
  * purpose:
  *  - provide an encryption algorithm to prevent password guessing.
  *  - passwords should be stored using one way encryption so the original
@@ -74,6 +67,7 @@ void owcrypt(const char * password, const char * salt, char * encrypted)
     switch (salt[OWCRYPT_SALT_SZ - 1])
     {
     case '0':
+        /* deprecated version */
         owcrypt0(password, salt, encrypted);
         break;
     case '1':
@@ -143,6 +137,7 @@ static void owcrypt1(
     }
 }
 
+/* deprecated */
 static void owcrypt0(
         const char * password,
         const char * salt,
index ea725b027035b9af01d65ce2de1ce25e53c1507c..ecbae05e4fda3dc735b49435da226c5d0ac52b3d 100644 (file)
@@ -6,13 +6,6 @@
  * http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-
  *      memory-consumption-from-inside-a-process
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-03-2016
- *
  */
 
 #include <stdlib.h>
index fb8e1a3ae9437faf6cc6058ba6b7d6977590795b..1b42207be706b7a69a1b75aab2f785bb09ca8a13 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * qpack.c - efficient binary serialization format
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 11-03-2016
- *          ((l + n) // 4 + 1) * 4
+ * qpack.c - Efficient binary serialization format.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
diff --git a/src/siri/admin/account.c b/src/siri/admin/account.c
deleted file mode 100644 (file)
index b5dbd63..0000000
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * account.c - SiriDB Administrative User.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2017
- *
- */
-#include <siri/admin/account.h>
-#include <stddef.h>
-#include <owcrypt/owcrypt.h>
-#include <xpath/xpath.h>
-#include <siri/siri.h>
-#include <stdarg.h>
-#include <logger/logger.h>
-
-#define SIRI_ADMIN_ACCOUNT_SCHEMA 1
-#define FILENAME ".accounts.dat"
-
-#define DEFAULT_ACCOUNT "sa"
-#define DEFAULT_PASSWORD "siri"
-
-static int ACCOUNT_free(siri_admin_account_t * account, void * args);
-static int ACCOUNT_save(siri_admin_account_t * account, qp_fpacker_t * fpacker);
-static void ACCOUNT_msg(char * err_msg, char * fmt, ...);
-static int ACCOUNT_cmp(
-        siri_admin_account_t * account,
-        qp_obj_t * qp_account);
-
-/*
- * Initialize siri->accounts. Returns 0 if successful or -1 in case of an error
- * (a signal might be raised because of qpack)
- */
-int siri_admin_account_init(siri_t * siri)
-{
-    qp_unpacker_t * unpacker;
-    qp_obj_t qp_schema;
-    qp_obj_t qp_account;
-    qp_obj_t qp_password;
-    int rc = 0;
-
-    /* get service accounts file name */
-    char fn[strlen(siri->cfg->default_db_path) + strlen(FILENAME) + 1];
-
-    /* initialize linked list */
-    siri->accounts = llist_new();
-    if (siri->accounts == NULL)
-    {
-        return -1;
-    }
-
-    /* make filename */
-    sprintf(fn, "%s%s", siri->cfg->default_db_path, FILENAME);
-
-    if (!xpath_file_exist(fn))
-    {
-        /* missing file, lets create the first account */
-        qp_account.via.raw = (unsigned char *) DEFAULT_ACCOUNT;
-        qp_account.len = 4;
-        qp_password.via.raw = (unsigned char *) DEFAULT_PASSWORD;
-        qp_password.len = 4;
-
-        return (siri_admin_account_new(
-                siri,
-                &qp_account,
-                &qp_password,
-                0,
-                NULL) || siri_admin_account_save(siri, NULL));
-    }
-
-    if ((unpacker = qp_unpacker_ff(fn)) == NULL)
-    {
-        return -1;  /* a signal is raised is case of a memory error */
-    }
-
-    if (    !qp_is_array(qp_next(unpacker, NULL)) ||
-            qp_next(unpacker, &qp_schema) != QP_INT64 ||
-            qp_schema.via.int64 != SIRI_ADMIN_ACCOUNT_SCHEMA)
-    {
-        log_critical("Invalid schema detected in '%s'", fn);
-        qp_unpacker_ff_free(unpacker);
-        return -1;
-    }
-
-    while ( rc == 0 &&
-            qp_is_array(qp_next(unpacker, NULL)) &&
-            qp_next(unpacker, &qp_account) == QP_RAW &&
-            qp_next(unpacker, &qp_password) == QP_RAW &&
-            qp_password.len > 12)  /* old and new passwords are > 12 */
-    {
-        rc = siri_admin_account_new(siri, &qp_account, &qp_password, 1, NULL);
-    }
-
-    qp_unpacker_ff_free(unpacker);
-    return rc;
-}
-
-/*
- * Creates a new service account and returns 0 if successful. In case of
- * an error, -1 is returned, err_msg is set.
- *
- * When successful, the account is added to the siri->accounts linked list.
- *
- * is_encrypted should be zero if the password is not encrypted yet.
- *
- * Note: the account will not be saved to disk. Call siri_admin_account_save()
- *       to save a new service account.
- */
-int siri_admin_account_new(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        qp_obj_t * qp_password,
-        int is_encrypted,
-        char * err_msg)
-{
-    siri_admin_account_t * account;
-
-    account = (siri_admin_account_t *) llist_get(
-            siri->accounts,
-            (llist_cb) ACCOUNT_cmp,
-            (void *) qp_account);
-
-    if (account != NULL)
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "service account '%.*s' already exists",
-                (int) qp_account->len,
-                qp_account->via.raw);
-        return -1;
-    }
-
-    if (qp_account->len < 2)
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "service account name should have at least 2 characters");
-        return -1;
-    }
-
-    if (qp_password->len < 2)
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "service account password should have at least 2 characters");
-        return -1;
-    }
-
-    account = (siri_admin_account_t *) malloc(sizeof(siri_admin_account_t));
-    if (account == NULL)
-    {
-        ACCOUNT_msg(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    account->account = strndup(
-            (const char *) qp_account->via.raw, qp_account->len);
-    account->password = strndup(
-            (const char *) qp_password->via.raw, qp_password->len);
-
-    if (!is_encrypted && account->password != NULL)
-    {
-        char encrypted[OWCRYPT_SZ];
-        char salt[OWCRYPT_SALT_SZ];
-
-        /* generate a random salt */
-        owcrypt_gen_salt(salt);
-
-        /* encrypt the accounts password */
-        owcrypt(account->password, salt, encrypted);
-
-        /* replace with encrypted password */
-        free(account->password);
-        account->password = strdup(encrypted);
-    }
-
-    if (    account->account == NULL ||
-            account->password == NULL ||
-            llist_append(siri->accounts, account))
-    {
-        ACCOUNT_msg(err_msg, "memory allocation error");
-        return -1;
-    }
-    return 0;
-}
-
-/*
- * Returns 0 if the account/password is valid or another value if not.
- */
-int siri_admin_account_check(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        qp_obj_t * qp_password,
-        char * err_msg)
-{
-    siri_admin_account_t * account;
-    char pw[OWCRYPT_SZ];
-    char * password;
-
-    account = (siri_admin_account_t *) llist_get(
-            siri->accounts,
-            (llist_cb) ACCOUNT_cmp,
-            (void *) qp_account);
-
-    if (account == NULL)
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "cannot find service account '%.*s'",
-                (int) qp_account->len,
-                qp_account->via.raw);
-        return -1;
-    }
-
-    password= strndup(
-            (const char *) qp_password->via.raw, qp_password->len);
-
-    if (password == NULL)
-    {
-        ACCOUNT_msg(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    owcrypt(password, account->password, pw);
-    free(password);
-
-    if (strcmp(pw, account->password))
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "incorrect password for service account '%.*s'",
-                (int) qp_account->len,
-                qp_account->via.raw);
-        return -1;
-    }
-
-    return 0;
-}
-
-/*
- * Returns 0 if the password is successful changed or -1 if not.
- *
- * Note: the password change is not saved, call siri_admin_account_save().
- */
-int siri_admin_account_change_password(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        qp_obj_t * qp_password,
-        char * err_msg)
-{
-    siri_admin_account_t * account;
-    char encrypted[OWCRYPT_SZ];
-    char salt[OWCRYPT_SALT_SZ];
-    char * password;
-
-    account = (siri_admin_account_t *) llist_get(
-            siri->accounts,
-            (llist_cb) ACCOUNT_cmp,
-            (void *) qp_account);
-
-    if (account == NULL)
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "cannot find service account '%.*s'",
-                (int) qp_account->len,
-                qp_account->via.raw);
-        return -1;
-    }
-
-    password= strndup(
-            (const char *) qp_password->via.raw, qp_password->len);
-
-    if (password == NULL)
-    {
-        ACCOUNT_msg(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    /* generate a random salt */
-    owcrypt_gen_salt(salt);
-
-    /* encrypt the accounts password */
-    owcrypt(password, salt, encrypted);
-
-    free(password);
-
-    password = strdup(encrypted);
-    if (password == NULL)
-    {
-        ACCOUNT_msg(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    /* replace account password with new encrypted password */
-    free(account->password);
-    account->password = password;
-
-    return 0;
-}
-
-/*
- * Returns 0 if dropped or -1 in case the account was not found.
- *
- * Note: accounts are not saved, call siri_admin_account_save().
- */
-int siri_admin_account_drop(
-        siri_t * siri,
-        qp_obj_t * qp_account,
-        char * err_msg)
-{
-    siri_admin_account_t * account;
-    account = (siri_admin_account_t *) llist_remove(
-            siri->accounts,
-            (llist_cb) ACCOUNT_cmp,
-            (void *) qp_account);
-    if (account == NULL)
-    {
-        ACCOUNT_msg(
-                err_msg,
-                "cannot find service account '%.*s'",
-                (int) qp_account->len,
-                qp_account->via.raw);
-        return -1;
-    }
-
-    ACCOUNT_free(account, NULL);
-    return 0;
-}
-
-/*
- * Destroy service accounts. siri->accounts is allowed to be NULL.
- */
-void siri_admin_account_destroy(siri_t * siri)
-{
-    if (siri->accounts != NULL)
-    {
-        llist_free_cb(siri->accounts, (llist_cb) ACCOUNT_free, NULL);
-    }
-}
-
-/*
- * Returns 0 if successful or EOF if not.
- */
-int siri_admin_account_save(siri_t * siri, char * err_msg)
-{
-    qp_fpacker_t * fpacker;
-
-    /* get service accounts file name */
-    char fn[strlen(siri->cfg->default_db_path) + strlen(FILENAME) + 1];
-
-    /* make filename */
-    sprintf(fn, "%s%s", siri->cfg->default_db_path, FILENAME);
-
-    if (
-        /* open a new account file */
-        (fpacker = qp_open(fn, "w")) == NULL ||
-
-        /* open a new array */
-        qp_fadd_type(fpacker, QP_ARRAY_OPEN) ||
-
-        /* write the current schema */
-        qp_fadd_int16(fpacker, SIRI_ADMIN_ACCOUNT_SCHEMA) ||
-
-        /* we can and should skip this if we have no accounts to save */
-        llist_walk(siri->accounts, (llist_cb) ACCOUNT_save, fpacker) ||
-
-        /* close file pointer */
-        qp_close(fpacker))
-    {
-        ACCOUNT_msg(err_msg, "error saving service accounts");
-        return EOF;
-    }
-    return 0;
-}
-
-/*
- * Destroy an account.
- */
-static int ACCOUNT_free(
-        siri_admin_account_t * account,
-        void * args __attribute__((unused)))
-{
-    free(account->account);
-    free(account->password);
-    free(account);
-    return 0;
-}
-
-/*
- * Returns 0 if successful and -1 in case an error occurred.
- */
-static int ACCOUNT_save(siri_admin_account_t * account, qp_fpacker_t * fpacker)
-{
-    int rc = 0;
-
-    rc += qp_fadd_type(fpacker, QP_ARRAY2);
-    rc += qp_fadd_string(fpacker, account->account);
-    rc += qp_fadd_string(fpacker, account->password);
-
-    return rc;
-}
-
-static void ACCOUNT_msg(char * err_msg, char * fmt, ...)
-{
-    va_list args;
-    va_start(args, fmt);
-    if (err_msg != NULL)
-    {
-        vsnprintf(err_msg, SIRI_MAX_SIZE_ERR_MSG, fmt, args);
-    }
-    else
-    {
-        log_error(fmt, args);
-    }
-    va_end(args);
-}
-
-static int ACCOUNT_cmp(
-        siri_admin_account_t * account,
-        qp_obj_t * qp_account)
-{
-    size_t len = strlen(account->account);
-    return (len == qp_account->len && strncmp(
-            account->account,
-            (const char *) qp_account->via.raw,
-            len) == 0);
-}
diff --git a/src/siri/admin/client.c b/src/siri/admin/client.c
deleted file mode 100644 (file)
index d246e5e..0000000
+++ /dev/null
@@ -1,1244 +0,0 @@
-/*
- * client.c - Client for expanding a siridb database.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 24-03-2017
- *
- */
-#include <string.h>
-#include <stdarg.h>
-#include <lock/lock.h>
-#include <logger/logger.h>
-#include <siri/siri.h>
-#include <siri/version.h>
-#include <siri/admin/client.h>
-#include <siri/admin/request.h>
-#include <siri/net/stream.h>
-#include <siri/net/protocol.h>
-#include <siri/net/tcp.h>
-#include <siri/db/server.h>
-
-/* 15 seconds  */
-#define CLIENT_REQUEST_TIMEOUT 15000
-#define CLIENT_FLAGS_TIMEOUT 1
-#define CLIENT_FLAGS_NO_ROLLBACK 2
-#define MAX_VERSION_LEN 256
-
-enum
-{
-    CLIENT_REQUEST_INIT,
-    CLIENT_REQUEST_STATUS,
-    CLIENT_REQUEST_POOLS,
-    CLIENT_REQUEST_FILE_USERS,
-    CLIENT_REQUEST_FILE_GROUPS,
-    CLIENT_REQUEST_FILE_SERVERS,
-    CLIENT_REQUEST_FILE_DATABASE,
-    CLIENT_REQUEST_REGISTER_SERVER
-};
-
-static void CLIENT_write_cb(uv_write_t * req, int status);
-static void CLIENT_on_connect(uv_connect_t * req, int status);
-static void CLIENT_on_data(sirinet_stream_t * client, sirinet_pkg_t * pkg);
-static void CLIENT_request_timeout(uv_timer_t * handle);
-static void CLIENT_on_auth_success(siri_admin_client_t * adm_client);
-static int CLIENT_resolve_dns(
-        siri_admin_client_t * adm_client,
-        int ai_family,
-        char * err_msg);
-static void CLIENT_on_resolved(
-        uv_getaddrinfo_t * resolver,
-        int status,
-        struct addrinfo * res);
-static void CLIENT_err(
-        siri_admin_client_t * adm_client,
-        const char * fmt,
-        ...);
-static void CLIENT_send_pkg(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_error_msg(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_register_server(siri_admin_client_t * adm_client);
-static void CLIENT_on_file_database(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_file_servers(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_file_groups(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_file_users(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_request_pools(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-static void CLIENT_on_request_status(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg);
-
-/*
- * Initializes a request for a new pool or replica and returns 0 when
- * successful. In case of an error, err_msg will be set and a value other than
- * 0 is returned. (a signal can be raised.) When successful and only when
- * successful, a response will be send to the provided client using the given
- * pid.
- */
-int siri_admin_client_request(
-        uint16_t pid,
-        uint16_t port,
-        int pool,
-        uuid_t * uuid,
-        qp_obj_t * host,
-        qp_obj_t * username,
-        qp_obj_t * password,
-        qp_obj_t * dbname,
-        const char * dbpath,
-        sirinet_stream_t * client,
-        char * err_msg)
-{
-    siri_admin_client_t * adm_client;
-    struct in_addr sa;
-    struct in6_addr sa6;
-
-    if (siri.client != NULL)
-    {
-        sprintf(err_msg, "manage socket already in use");
-        return -1;
-    }
-
-    siri.client = sirinet_stream_new(STREAM_TCP_MANAGE, &CLIENT_on_data);
-    if (siri.client == NULL)
-    {
-        sprintf(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    uv_tcp_init(siri.loop, (uv_tcp_t *) siri.client->stream);
-
-    adm_client = (siri_admin_client_t *) malloc(sizeof(siri_admin_client_t));
-    if (adm_client == NULL)
-    {
-        sirinet_stream_decref(siri.client);
-        sprintf(err_msg, "memory allocation error");
-        return -1;
-    }
-    adm_client->pid = pid;
-    adm_client->port = port;
-    adm_client->host = strndup(
-            (const char *) host->via.raw, host->len);
-    adm_client->username = strndup(
-            (const char *) username->via.raw, username->len);
-    adm_client->password = strndup(
-            (const char *) password->via.raw, password->len);
-    adm_client->dbname = strndup(
-            (const char *) dbname->via.raw, dbname->len);
-    adm_client->dbpath = strdup(dbpath);
-    adm_client->client = client;
-    adm_client->request = CLIENT_REQUEST_INIT;
-    adm_client->flags = 0;
-    adm_client->pool = pool;
-    memcpy(&adm_client->uuid, uuid, 16);
-
-
-    siri.client->origin = (void *) adm_client;
-
-    sirinet_stream_incref(adm_client->client);
-
-    if (adm_client->host == NULL ||
-        adm_client->username == NULL ||
-        adm_client->password == NULL ||
-        adm_client->dbname == NULL ||
-        adm_client->dbpath == NULL)
-    {
-        sirinet_stream_decref(siri.client);
-        sprintf(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    if (inet_pton(AF_INET, adm_client->host, &sa))
-    {
-        /* IPv4 */
-        struct sockaddr_in dest;
-
-        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
-        if (req == NULL)
-        {
-            sirinet_stream_decref(siri.client);
-            sprintf(err_msg, "memory allocation error");
-            return -1;
-        }
-        log_debug(
-                "Trying to connect to '%s:%u'...",
-                adm_client->host,
-                adm_client->port);
-
-        uv_ip4_addr(adm_client->host, adm_client->port, &dest);
-        uv_tcp_connect(
-                req,
-                (uv_tcp_t *) siri.client->stream,
-                (const struct sockaddr *) &dest,
-                CLIENT_on_connect);
-    }
-    else if (inet_pton(AF_INET6, adm_client->host, &sa6))
-    {
-        /* IPv6 */
-        struct sockaddr_in6 dest6;
-
-        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
-        if (req == NULL)
-        {
-            sirinet_stream_decref(siri.client);
-            sprintf(err_msg, "memory allocation error");
-            return -1;
-        }
-        log_debug(
-                "Trying to connect to '%s:%u'...",
-                adm_client->host,
-                adm_client->port);
-        uv_ip6_addr(adm_client->host, adm_client->port, &dest6);
-        uv_tcp_connect(
-                req,
-                (uv_tcp_t *) siri.client->stream,
-                (const struct sockaddr *) &dest6,
-                CLIENT_on_connect);
-    }
-    else
-    {
-        if (CLIENT_resolve_dns(
-                adm_client,
-                dns_req_family_map[siri.cfg->ip_support],
-                err_msg))
-        {
-            sirinet_stream_decref(siri.client);
-            return -1;  /* err_msg is set */
-        }
-    }
-    uv_timer_init(siri.loop, &siri.timer);
-    return 0;
-}
-
-/*
- * Destroy the client request. (will be called when the socket is destroyed)
- */
-void siri_admin_client_free(siri_admin_client_t * adm_client)
-{
-    if (adm_client != NULL)
-    {
-        sirinet_stream_decref(adm_client->client);
-        free(adm_client->host);
-        free(adm_client->username);
-        free(adm_client->password);
-        free(adm_client->dbname);
-        free(adm_client->dbpath);
-        free(adm_client);
-    }
-}
-/*
- * Try to get an ip address from dns.
- *
- * This function should return 0 when we can start an attempt for discovering
- * dns. When the result is not zero, CLIENT_on_resolved will not be called and
- * err_msg is set.
- */
-static int CLIENT_resolve_dns(
-        siri_admin_client_t * adm_client,
-        int ai_family,
-        char * err_msg)
-{
-    struct addrinfo hints;
-    hints.ai_family = ai_family;
-    hints.ai_socktype = SOCK_STREAM;
-    hints.ai_protocol = IPPROTO_TCP;
-    hints.ai_flags = AI_NUMERICSERV;
-
-    uv_getaddrinfo_t * resolver =
-            (uv_getaddrinfo_t *) malloc(sizeof(uv_getaddrinfo_t));
-
-    if (resolver == NULL)
-    {
-        sprintf(err_msg, "memory allocation error");
-        return -1;
-    }
-
-    int result;
-    resolver->data = adm_client;
-
-    char port[6]= {'\0'};
-    sprintf(port, "%u", adm_client->port);
-
-    result = uv_getaddrinfo(
-            siri.loop,
-            resolver,
-            (uv_getaddrinfo_cb) CLIENT_on_resolved,
-            adm_client->host,
-            port,
-            &hints);
-
-    if (result)
-    {
-        snprintf(
-                err_msg,
-                SIRI_MAX_SIZE_ERR_MSG,
-                "getaddrinfo call error %s",
-                uv_err_name(result));
-        free(resolver);
-    }
-
-    return result;
-}
-
-/*
- * Callback used to check if resolving an ip address was successful.
- */
-static void CLIENT_on_resolved(
-        uv_getaddrinfo_t * resolver,
-        int status,
-        struct addrinfo * res)
-{
-    siri_admin_client_t * adm_client = (siri_admin_client_t *) resolver->data;
-
-    if (status < 0)
-    {
-        CLIENT_err(
-                adm_client,
-                "cannot resolve ip address for '%s' (error: %s)",
-                adm_client->host,
-                uv_err_name(status));
-    }
-    else
-    {
-        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
-        if (req == NULL)
-        {
-            CLIENT_err(adm_client, "memory allocation error");
-        }
-        else
-        {
-            uv_tcp_connect(
-                    req,
-                    (uv_tcp_t *) siri.client->stream,
-                    (const struct sockaddr *) res->ai_addr,
-                    CLIENT_on_connect);
-        }
-    }
-
-    uv_freeaddrinfo(res);
-    free(resolver);
-}
-
-/*
- * In case a client request fails, this function should be called to end
- * the request. A package with the error message will be send to the client.
- */
-static void CLIENT_err(
-        siri_admin_client_t * adm_client,
-        const char * fmt,
-        ...)
-{
-    char err_msg[SIRI_MAX_SIZE_ERR_MSG];
-
-    va_list args;
-    va_start(args, fmt);
-    vsnprintf(err_msg, SIRI_MAX_SIZE_ERR_MSG, fmt, args);
-    va_end(args);
-
-    sirinet_pkg_t * package = sirinet_pkg_err(
-            adm_client->pid,
-            strlen(err_msg),
-            CPROTO_ERR_ADMIN,
-            err_msg);
-
-    if (package != NULL)
-    {
-        sirinet_pkg_send(adm_client->client, package);
-    }
-
-    log_error(err_msg);
-
-    if (~adm_client->flags & CLIENT_FLAGS_NO_ROLLBACK)
-    {
-        siri_admin_request_rollback(adm_client->dbpath);
-    }
-
-    sirinet_stream_decref(siri.client);
-
-    uv_close((uv_handle_t *) &siri.timer, NULL);
-}
-
-/*
- * Send a package to the 'other' SiriDB server. This function can be used for
- * sending api requests for all database information required to create the
- * database. Note that all packages are send with the same pid so packages
- * should be send in sequence, not parallel.
- *
- * Note: pkg will be freed by calling this function.
- */
-static void CLIENT_send_pkg(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    uv_write_t * req = (uv_write_t *) malloc(sizeof(uv_write_t));
-    if (req == NULL)
-    {
-        free(pkg);
-        CLIENT_err(adm_client, "memory allocation error");
-    }
-    req->data = adm_client;
-
-    adm_client->pkg = pkg;
-
-    /* set the correct check bit */
-    pkg->checkbit = pkg->tp ^ 255;
-
-    uv_timer_start(
-            &siri.timer,
-            CLIENT_request_timeout,
-            CLIENT_REQUEST_TIMEOUT,
-            0);
-
-    siri.timer.data = adm_client;
-
-    uv_buf_t wrbuf = uv_buf_init(
-            (char *) pkg,
-            sizeof(sirinet_pkg_t) + pkg->len);
-
-    uv_write(
-            req,
-            siri.client->stream,
-            &wrbuf,
-            1,
-            CLIENT_write_cb);
-}
-
-/*
- * Write call-back.
- */
-static void CLIENT_write_cb(uv_write_t * req, int status)
-{
-    siri_admin_client_t * adm_client = (siri_admin_client_t *)  req->data;
-
-    if (status)
-    {
-        uv_timer_stop(&siri.timer);
-        CLIENT_err(adm_client, "socket write error: %s", uv_strerror(status));
-    }
-
-    free(adm_client->pkg);
-    free(req);
-}
-
-/*
- * Called when a connection to the 'other' siridb server is made.
- * An authentication request will be send by user/password since this will be
- * using the client connection. (a signal can be raised)
- */
-static void CLIENT_on_connect(uv_connect_t * req, int status)
-{
-    sirinet_stream_t * client = req->handle->data;
-    siri_admin_client_t * adm_client = client->origin;
-
-    if (status == 0)
-    {
-        log_debug(
-                "Connected to SiriDB server: '%s:%u', "
-                "sending authentication request",
-                adm_client->host, adm_client->port);
-
-        uv_read_start(
-                req->handle,
-                sirinet_stream_alloc_buffer,
-                sirinet_stream_on_data);
-
-        sirinet_pkg_t * pkg;
-        qp_packer_t * packer = sirinet_packer_new(512);
-
-        if (packer == NULL)
-        {
-            CLIENT_err(adm_client, "memory allocation error");
-        }
-        else
-        {
-            if (qp_add_type(packer, QP_ARRAY3) ||
-                qp_add_string(packer, adm_client->username) ||
-                qp_add_string(packer, adm_client->password) ||
-                qp_add_string(packer, adm_client->dbname))
-            {
-                qp_packer_free(packer);
-            }
-            else
-            {
-                pkg = sirinet_packer2pkg(packer, 0, CPROTO_REQ_AUTH);
-                CLIENT_send_pkg(adm_client, pkg);
-            }
-
-        }
-    }
-    else
-    {
-        CLIENT_err(
-                adm_client,
-                "connecting to server '%s:%u' failed with error: %s",
-                adm_client->host,
-                adm_client->port,
-                uv_strerror(status));
-    }
-    free(req);
-}
-
-/*
- * on-data call-back function.
- */
-static void CLIENT_on_data(sirinet_stream_t * client, sirinet_pkg_t * pkg)
-{
-    siri_admin_client_t * adm_client = client->origin;
-    log_debug(
-            "Client response received (pid: %" PRIu16
-            ", len: %" PRIu32 ", tp: %s)",
-            pkg->pid,
-            pkg->len,
-            sirinet_cproto_server_str(pkg->tp));
-
-    if (adm_client->flags & CLIENT_FLAGS_TIMEOUT)
-    {
-        log_error("Client response received which was timed-out earlier");
-    }
-    else
-    {
-        uv_timer_stop(&siri.timer);
-
-        switch ((cproto_server_t) pkg->tp)
-        {
-        case CPROTO_RES_AUTH_SUCCESS:
-            CLIENT_on_auth_success(adm_client);
-            break;
-        case CPROTO_RES_QUERY:
-            switch (adm_client->request)
-            {
-            case CLIENT_REQUEST_STATUS:
-                CLIENT_on_request_status(adm_client, pkg);
-                break;
-            case CLIENT_REQUEST_POOLS:
-                CLIENT_on_request_pools(adm_client, pkg);
-                break;
-            default:
-                CLIENT_err(adm_client, "unexpected query response");
-            }
-            break;
-        case CPROTO_RES_FILE:
-            switch (adm_client->request)
-            {
-            case CLIENT_REQUEST_FILE_USERS:
-                CLIENT_on_file_users(adm_client, pkg);
-                break;
-            case CLIENT_REQUEST_FILE_GROUPS:
-                CLIENT_on_file_groups(adm_client, pkg);
-                break;
-            case CLIENT_REQUEST_FILE_SERVERS:
-                CLIENT_on_file_servers(adm_client, pkg);
-                break;
-            case CLIENT_REQUEST_FILE_DATABASE:
-                CLIENT_on_file_database(adm_client, pkg);
-                break;
-            default:
-                CLIENT_err(adm_client, "unexpected query response");
-            }
-            break;
-        case CPROTO_RES_ACK:
-            switch (adm_client->request)
-            {
-            case CLIENT_REQUEST_REGISTER_SERVER:
-                CLIENT_on_register_server(adm_client);
-                break;
-            default:
-                CLIENT_err(adm_client, "unexpected query response");
-            }
-            break;
-        case CPROTO_ERR_AUTH_CREDENTIALS:
-            CLIENT_err(
-                    adm_client,
-                    "invalid credentials for database '%s' on server '%s:%u'",
-                    adm_client->dbname,
-                    adm_client->host,
-                    adm_client->port);
-            break;
-        case CPROTO_ERR_AUTH_UNKNOWN_DB:
-            CLIENT_err(
-                    adm_client,
-                    "database '%s' does not exist on server '%s:%u'",
-                    adm_client->dbname,
-                    adm_client->host,
-                    adm_client->port);
-            break;
-        case CPROTO_ERR_MSG:
-        case CPROTO_ERR_QUERY:
-        case CPROTO_ERR_INSERT:
-        case CPROTO_ERR_SERVER:
-        case CPROTO_ERR_POOL:
-        case CPROTO_ERR_USER_ACCESS:
-            CLIENT_on_error_msg(adm_client, pkg);
-            break;
-        default:
-            CLIENT_err(
-                    adm_client,
-                    "unexpected response (%u) received from server '%s:%u'",
-                    pkg->tp,
-                    adm_client->host,
-                    adm_client->port);
-        }
-    }
-}
-
-/*
- * Called when register server was successful.
- */
-static void CLIENT_on_register_server(siri_admin_client_t * adm_client)
-{
-    sirinet_pkg_t * package = sirinet_pkg_new(
-            adm_client->pid,
-            0,
-            CPROTO_ACK_ADMIN,
-            NULL);
-
-    if (package != NULL)
-    {
-        sirinet_pkg_send(adm_client->client, package);
-    }
-
-    log_info(
-            "Finished registering server on database '%s'",
-            adm_client->dbname);
-
-    sirinet_stream_decref(siri.client);
-    uv_close((uv_handle_t *) &siri.timer, NULL);
-}
-
-/*
- * Called when database.dat is received.
- */
-static void CLIENT_on_file_database(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    FILE * fp;
-    qp_unpacker_t unpacker;
-    qp_obj_t qp_uuid;
-    siridb_t * siridb;
-    int rc;
-    /* 13 = strlen("database.dat")+1  */
-    char fn[strlen(adm_client->dbpath) + 13];
-    sprintf(fn, "%sdatabase.dat", adm_client->dbpath);
-
-    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
-
-    if (qp_is_array(qp_next(&unpacker, NULL)) &&
-        /* schema check is not required at this moment but can be done here */
-        qp_next(&unpacker, NULL) == QP_INT64 &&
-        qp_next(&unpacker, &qp_uuid) == QP_RAW &&
-        qp_uuid.len == 16)
-    {
-        memcpy(unpacker.pt - 16, &adm_client->uuid, 16);
-    }
-    else
-    {
-        CLIENT_err(adm_client, "invalid database file received");
-        return;
-    }
-
-    fp = fopen(fn, "w");
-
-    if (fp == NULL)
-    {
-        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
-        return;
-    }
-
-    rc = fwrite(pkg->data, pkg->len, 1, fp);
-
-    if (fclose(fp) || rc != 1)
-    {
-        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
-        return;
-    }
-
-    siridb = siridb_new(adm_client->dbpath, LOCK_QUIT_IF_EXIST);
-
-    if (siridb == NULL)
-    {
-        CLIENT_err(adm_client, "error loading database");
-        return;
-    }
-
-    /* roll-back is not possible anymore */
-    adm_client->flags |= CLIENT_FLAGS_NO_ROLLBACK;
-
-    siridb->server->flags |= SERVER_FLAG_RUNNING;
-
-    /* Force one heart-beat */
-    siri_heartbeat_force();
-
-    sirinet_pkg_t * package;
-    qp_packer_t * packer = sirinet_packer_new(512);
-
-    if (packer == NULL)
-    {
-        CLIENT_err(adm_client, "memory allocation error");
-        return;
-    }
-
-    adm_client->request = CLIENT_REQUEST_REGISTER_SERVER;
-
-    if (qp_add_type(packer, QP_ARRAY4) ||
-        qp_add_raw(packer, (const unsigned char *) &adm_client->uuid, 16) ||
-        qp_add_string(packer, siri.cfg->server_address) ||
-        qp_add_int32(packer, (int32_t) siri.cfg->listen_backend_port) ||
-        qp_add_int32(packer, (int32_t) adm_client->pool))
-    {
-        qp_packer_free(packer);
-        CLIENT_err(adm_client, "memory allocation error");
-        return;
-    }
-
-    package = sirinet_packer2pkg(packer, 0, CPROTO_REQ_REGISTER_SERVER);
-    CLIENT_send_pkg(adm_client, package);
-}
-
-/*
- * Called when servers.dat is received.
- */
-static void CLIENT_on_file_servers(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    FILE * fp;
-    qp_unpacker_t unpacker;
-    qp_types_t tp;
-    int rc, n, close_num;
-    /* 12 = strlen("servers.dat") + 1  */
-    char fn[strlen(adm_client->dbpath) + 12];
-    sprintf(fn, "%sservers.dat", adm_client->dbpath);
-
-    fp = fopen(fn, "w");
-    if (fp == NULL)
-    {
-        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
-        return;
-    }
-
-    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
-    tp = qp_next(&unpacker, NULL);
-    if (tp >= QP_ARRAY0 && tp <= QP_ARRAY5)
-    {
-        pkg->data[0] = QP_ARRAY_OPEN;
-    }
-    else if (tp != QP_ARRAY_OPEN)
-    {
-        CLIENT_err(adm_client, "invalid server status response");
-        return;
-    }
-
-    /* schema checking is not required at this moment but can be done here */
-    qp_next(&unpacker, NULL);
-
-    tp = qp_next(&unpacker, NULL);
-
-    if (!qp_is_array(tp))
-    {
-        CLIENT_err(adm_client, "invalid server status response");
-        return;
-    }
-
-    close_num = (tp == QP_ARRAY_OPEN) ? 1 : 0;
-
-    /* trim closing */
-    for (n = pkg->len;
-         (unsigned char) pkg->data[n - 1] == QP_ARRAY_CLOSE;
-         n--);
-
-    rc = (fwrite(pkg->data, n, 1, fp) == 1) ? 0 : EOF;
-
-    if (close_num)
-    {
-        rc += qp_fadd_type(fp, QP_ARRAY_CLOSE);
-    }
-
-    rc += qp_fadd_type(fp, QP_ARRAY4);
-    rc += qp_fadd_raw(fp, (const unsigned char *) &adm_client->uuid, 16);
-    rc += qp_fadd_string(fp, siri.cfg->server_address);
-    rc += qp_fadd_int32(fp, (int32_t) siri.cfg->listen_backend_port);
-    rc += qp_fadd_int32(fp, (int32_t) adm_client->pool);
-    rc += fclose(fp);
-
-    if (rc)
-    {
-        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
-    }
-    else
-    {
-        sirinet_pkg_t * package;
-        adm_client->request = CLIENT_REQUEST_FILE_DATABASE;
-        package = sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_DATABASE, NULL);
-        if (package == NULL)
-        {
-            CLIENT_err(adm_client, "memory allocation error");
-        }
-        else
-        {
-            CLIENT_send_pkg(adm_client, package);
-        }
-    }
-}
-
-/*
- * Called when groups.dat is received.
- */
-static void CLIENT_on_file_groups(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    FILE * fp;
-    /* 11 = strlen("groups.dat") + 1  */
-    char fn[strlen(adm_client->dbpath) + 11];
-    sprintf(fn, "%sgroups.dat", adm_client->dbpath);
-
-    fp = fopen(fn, "w");
-    if (fp == NULL)
-    {
-        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
-    }
-    else
-    {
-        int rc = fwrite(pkg->data, pkg->len, 1, fp);
-
-        if (fclose(fp) || rc != 1)
-        {
-            CLIENT_err(adm_client, "cannot write data to file: %s", fn);
-        }
-        else
-        {
-            adm_client->request = CLIENT_REQUEST_FILE_SERVERS;
-            sirinet_pkg_t * package =
-                    sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_SERVERS, NULL);
-            if (package == NULL)
-            {
-                CLIENT_err(adm_client, "memory allocation error");
-            }
-            else
-            {
-                CLIENT_send_pkg(adm_client, package);
-            }
-        }
-    }
-}
-
-/*
- * Called when users.dat is received.
- */
-static void CLIENT_on_file_users(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    FILE * fp;
-    /* 10 = strlen("users.dat") + 1  */
-    char fn[strlen(adm_client->dbpath) + 10];
-    sprintf(fn, "%susers.dat", adm_client->dbpath);
-
-    fp = fopen(fn, "w");
-    if (fp == NULL)
-    {
-        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
-    }
-    else
-    {
-        int rc = fwrite(pkg->data, pkg->len, 1, fp);
-
-        if (fclose(fp) || rc != 1)
-        {
-            CLIENT_err(adm_client, "cannot write data to file: %s", fn);
-        }
-        else
-        {
-            adm_client->request = CLIENT_REQUEST_FILE_GROUPS;
-            sirinet_pkg_t * package =
-                    sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_GROUPS, NULL);
-            if (package == NULL)
-            {
-                CLIENT_err(adm_client, "memory allocation error");
-            }
-            else
-            {
-                CLIENT_send_pkg(adm_client, package);
-            }
-        }
-    }
-}
-
-/*
- * Called when 'list pools ...' response is received.
- * This function will check which pool number will be assigned for a new pool
- * or checks if a given pool for a new replica is valid.
- */
-static void CLIENT_on_request_pools(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    qp_unpacker_t unpacker;
-    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
-    qp_obj_t qp_val;
-    qp_obj_t qp_pool;
-    qp_obj_t qp_servers;
-    int columns_found = 0;
-    int validate_pool = -1;
-
-    if (!qp_is_map(qp_next(&unpacker, NULL)))
-    {
-        CLIENT_err(adm_client, "invalid server status response");
-        return;
-    }
-
-    qp_next(&unpacker, &qp_val);
-
-    while (qp_val.tp == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_val.via.raw,
-                    "columns",
-                    qp_val.len) == 0 &&
-                qp_is_array(qp_next(&unpacker, NULL)) &&
-                qp_next(&unpacker, &qp_val) == QP_RAW &&
-                strncmp(
-                    (const char *) qp_val.via.raw, "pool", qp_val.len) == 0 &&
-                qp_next(&unpacker, &qp_val) == QP_RAW &&
-                strncmp(
-                    (const char *) qp_val.via.raw, "servers", qp_val.len) == 0)
-        {
-            if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
-            {
-                qp_next(&unpacker, &qp_val);
-            }
-            columns_found = 1;
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_val.via.raw, "pools", qp_val.len) == 0 &&
-                qp_is_array(qp_next(&unpacker, NULL)))
-        {
-            qp_next(&unpacker, &qp_val);
-
-            while (qp_is_array(qp_val.tp))
-            {
-                if (qp_next(&unpacker, &qp_pool) == QP_INT64 &&
-                    qp_next(&unpacker, &qp_servers) == QP_INT64)
-                {
-                    if (adm_client->pool < 0)
-                    {
-                        /* looking for a new pool */
-                        if (qp_pool.via.int64 > validate_pool)
-                        {
-                            validate_pool = qp_pool.via.int64;
-                        }
-                    }
-                    else
-                    {
-                        if (qp_pool.via.int64 == adm_client->pool)
-                        {
-                            if (qp_servers.via.int64 > 1)
-                            {
-                                CLIENT_err(
-                                        adm_client,
-                                        "pool %d has already %" PRId64
-                                        " servers",
-                                        adm_client->pool,
-                                        qp_servers.via.int64);
-                                return;
-                            }
-                            else
-                            {
-                                validate_pool = 0;
-                            }
-                        }
-                    }
-                }
-                else
-                {
-                    CLIENT_err(adm_client, "invalid server status response");
-                    return;
-                }
-                if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
-                {
-                    qp_next(&unpacker, &qp_val);
-                }
-            }
-            if (qp_val.tp == QP_ARRAY_CLOSE)
-            {
-                qp_next(&unpacker, &qp_val);
-            }
-            continue;
-        }
-
-        CLIENT_err(adm_client, "invalid server status response");
-        return;
-    }
-
-    if (!columns_found)
-    {
-        CLIENT_err(adm_client, "invalid server status response");
-    }
-    else
-    {
-        sirinet_pkg_t * package;
-
-        if (adm_client->pool < 0)
-        {
-            if (validate_pool == -1)
-            {
-                CLIENT_err(adm_client, "invalid server status response");
-                return;
-            }
-            /* set new correct pool in case we request a new pool */
-            adm_client->pool = validate_pool + 1;
-        }
-        else if (validate_pool == -1)
-        {
-            CLIENT_err(
-                    adm_client,
-                    "pool %d does not exist",
-                    adm_client->pool);
-            return;
-        }
-
-        adm_client->request = CLIENT_REQUEST_FILE_USERS;
-        package = sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_USERS, NULL);
-        if (package == NULL)
-        {
-            CLIENT_err(adm_client, "memory allocation error");
-        }
-        else
-        {
-            CLIENT_send_pkg(adm_client, package);
-        }
-    }
-}
-
-/*
- * Called when 'list servers ...' response is received.
- * This function will check if each current server has status running.
- * (this is a pre-check, the final register call does check for all servers
- * to have the running status once more)
- */
-static void CLIENT_on_request_status(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    qp_unpacker_t unpacker;
-    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
-    qp_obj_t qp_val;
-    qp_obj_t qp_name;
-    qp_obj_t qp_status;
-    qp_obj_t qp_version;
-    int columns_found = 0;
-    int servers_found = 0;
-    char version[MAX_VERSION_LEN];
-
-    if (!qp_is_map(qp_next(&unpacker, NULL)))
-    {
-        CLIENT_err(adm_client, "invalid server status response");
-        return;
-    }
-
-    qp_next(&unpacker, &qp_val);
-
-    while (qp_val.tp == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_val.via.raw,
-                    "columns",
-                    qp_val.len) == 0 &&
-                qp_is_array(qp_next(&unpacker, NULL)) &&
-                qp_next(&unpacker, &qp_val) == QP_RAW &&
-                strncmp(
-                    (const char *) qp_val.via.raw, "name", qp_val.len) == 0 &&
-                qp_next(&unpacker, &qp_val) == QP_RAW &&
-                strncmp(
-                    (const char *) qp_val.via.raw,
-                    "status",
-                    qp_val.len) == 0 &&
-                qp_next(&unpacker, &qp_val) == QP_RAW &&
-                strncmp(
-                    (const char *) qp_val.via.raw, "version", qp_val.len) == 0)
-        {
-            if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
-            {
-                qp_next(&unpacker, &qp_val);
-            }
-            columns_found = 1;
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_val.via.raw,
-                    "servers",
-                    qp_val.len) == 0 &&
-                qp_is_array(qp_next(&unpacker, NULL)))
-        {
-            qp_next(&unpacker, &qp_val);
-
-            while (qp_is_array(qp_val.tp))
-            {
-                if (qp_next(&unpacker, &qp_name) == QP_RAW &&
-                    qp_next(&unpacker, &qp_status) == QP_RAW &&
-                    qp_next(&unpacker, &qp_version) == QP_RAW &&
-                    qp_version.len < MAX_VERSION_LEN)
-                {
-                    /* copy and null terminate version */
-                    memcpy(version, qp_version.via.raw, qp_version.len);
-                    version[qp_version.len] = '\0';
-
-                    if (siri_version_cmp(version, SIRIDB_VERSION))
-                    {
-                        CLIENT_err(
-                                adm_client,
-                                "server '%.*s' is running on version %s "
-                                "while version %s is expected. (all SiriBD "
-                                "servers should run the same version)",
-                                (int) qp_name.len,
-                                qp_name.via.raw,
-                                version,
-                                SIRIDB_VERSION);
-                        return;
-                    }
-
-                    if (strncmp(
-                            (const char *) qp_status.via.raw,
-                            "running",
-                            qp_status.len) != 0)
-                    {
-                        CLIENT_err(
-                                adm_client,
-                                "server '%.*s' has status: '%.*s'",
-                                (int) qp_name.len,
-                                qp_name.via.raw,
-                                (int) qp_status.len,
-                                qp_status.via.raw);
-                        return;
-                    }
-                    servers_found++;
-                }
-                else
-                {
-                    CLIENT_err(adm_client, "invalid server status response");
-                    return;
-                }
-                if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
-                {
-                    qp_next(&unpacker, &qp_val);
-                }
-            }
-            if (qp_val.tp == QP_ARRAY_CLOSE)
-            {
-                qp_next(&unpacker, &qp_val);
-            }
-            continue;
-        }
-
-        CLIENT_err(adm_client, "invalid server status response");
-        return;
-    }
-
-    if (!servers_found || !columns_found)
-    {
-        CLIENT_err(adm_client, "invalid server status response");
-    }
-    else
-    {
-        sirinet_pkg_t * package;
-        qp_packer_t * packer = sirinet_packer_new(512);
-        if (packer == NULL)
-        {
-            CLIENT_err(adm_client, "memory allocation error");
-        }
-        else
-        {
-            adm_client->request = CLIENT_REQUEST_POOLS;
-
-            /* no need to check since this will always fit */
-            qp_add_type(packer, QP_ARRAY1);
-            qp_add_string(packer, "list pools pool, servers");
-            package = sirinet_packer2pkg(packer, 0, CPROTO_REQ_QUERY);
-            CLIENT_send_pkg(adm_client, package);
-        }
-    }
-}
-
-/*
- * Called when an error message is received.
- */
-static void CLIENT_on_error_msg(
-        siri_admin_client_t * adm_client,
-        sirinet_pkg_t * pkg)
-{
-    qp_unpacker_t unpacker;
-    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
-    qp_obj_t qp_err;
-
-    if (qp_is_map(qp_next(&unpacker, NULL)) &&
-        qp_next(&unpacker, NULL) == QP_RAW &&
-        qp_next(&unpacker, &qp_err) == QP_RAW)
-    {
-        CLIENT_err(
-                adm_client,
-                "error on server '%s:%u': %.*s",
-                adm_client->host,
-                adm_client->port,
-                (int) qp_err.len,
-                qp_err.via.raw);
-    }
-    else
-    {
-        CLIENT_err(
-                adm_client,
-                "unexpected error on server '%s:%u'",
-                adm_client->host,
-                adm_client->port);
-    }
-}
-
-/*
- * Called when authentication is successful.
- */
-static void CLIENT_on_auth_success(siri_admin_client_t * adm_client)
-{
-    sirinet_pkg_t * pkg;
-    qp_packer_t * packer = sirinet_packer_new(512);
-    if (packer == NULL)
-    {
-        CLIENT_err(adm_client, "memory allocation error");
-    }
-    else
-    {
-        adm_client->request = CLIENT_REQUEST_STATUS;
-
-        /* no need to check since this will always fit */
-        qp_add_type(packer, QP_ARRAY1);
-        qp_add_string(packer, "list servers name, status, version");
-        pkg = sirinet_packer2pkg(packer, 0, CPROTO_REQ_QUERY);
-        CLIENT_send_pkg(adm_client, pkg);
-    }
-}
-
-/*
- * Timeout on a client request.
- */
-static void CLIENT_request_timeout(uv_timer_t * handle)
-{
-    siri_admin_client_t * adm_client = (siri_admin_client_t *) handle->data;
-
-    adm_client->flags |= CLIENT_FLAGS_TIMEOUT;
-
-    CLIENT_err(adm_client, "request timeout");
-}
diff --git a/src/siri/admin/request.c b/src/siri/admin/request.c
deleted file mode 100644 (file)
index 8b92695..0000000
+++ /dev/null
@@ -1,998 +0,0 @@
-/*
- * request.c - SiriDB Administrative Request.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2017, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2017
- *
- */
-
-#define PCRE2_CODE_UNIT_WIDTH 8
-
-#include <siri/admin/account.h>
-#include <siri/admin/client.h>
-#include <stddef.h>
-#include <siri/admin/request.h>
-#include <siri/siri.h>
-#include <logger/logger.h>
-#include <pcre2.h>
-#include <lock/lock.h>
-#include <xmath/xmath.h>
-#include <unistd.h>
-#include <uuid/uuid.h>
-#include <siri/db/server.h>
-#include <siri/db/buffer.h>
-#include <siri/version.h>
-#include <siri/db/reindex.h>
-
-#define DEFAULT_TIME_PRECISION 1
-#define DEFAULT_BUFFER_SIZE 1024
-#define DEFAULT_DURATION_NUM 604800
-#define DEFAULT_DURATION_LOG 86400
-#define DB_CONF_FN "database.conf"
-#define DB_DAT_FN "database.dat"
-#define DEFAULT_CONF \
-"#\n" \
-"# Welcome to the SiriDB configuration file\n" \
-"#\n" \
-"\n" \
-"[buffer]\n" \
-"# Alternative path to save the buffer file.\n" \
-"# In case you later plan to change this location you manually need to move\n" \
-"# the buffer file to the new location.\n" \
-"# path = <buffer_path>\n" \
-"\n" \
-"# Buffer size in bytes. This size must be a multiple of 512 with a maximum\n" \
-"# of 1048576 bytes. Be careful using large values since SiriDB will require\n" \
-"# memory based on this value. A value between 1024 and 32768 is recommended.\n" \
-"# size = 1024\n"
-
-#define CHECK_DBNAME_AND_CREATE_PATH                                        \
-    pcre_exec_ret = pcre2_match(                                            \
-            siri.dbname_regex,                                              \
-            (PCRE2_SPTR8) qp_dbname.via.raw,                                \
-            qp_dbname.len,                                                  \
-            0,                                                              \
-            0,                                                              \
-            siri.dbname_match_data,                                         \
-            NULL);                                                          \
-                                                                            \
-    if (pcre_exec_ret < 0)                                                  \
-    {                                                                       \
-        snprintf(                                                           \
-                err_msg,                                                    \
-                SIRI_MAX_SIZE_ERR_MSG,                                      \
-                "invalid database name: '%.*s'",                            \
-                (int) qp_dbname.len,                                        \
-                qp_dbname.via.raw);                                         \
-        return CPROTO_ERR_ADMIN;                                            \
-    }                                                                       \
-                                                                            \
-    if (llist_get(                                                          \
-            siri.siridb_list,                                               \
-            (llist_cb) ADMIN_find_database,                                 \
-            &qp_dbname) != NULL)                                            \
-    {                                                                       \
-        snprintf(                                                           \
-                err_msg,                                                    \
-                SIRI_MAX_SIZE_ERR_MSG,                                      \
-                "database name already exists: '%.*s'",                     \
-                (int) qp_dbname.len,                                        \
-                qp_dbname.via.raw);                                         \
-        return CPROTO_ERR_ADMIN;                                            \
-    }                                                                       \
-                                                                            \
-    dbpath_len = strlen(siri.cfg->default_db_path) + qp_dbname.len + 2;     \
-    char dbpath[dbpath_len];                                                \
-    sprintf(dbpath,                                                         \
-            "%s%.*s/",                                                      \
-            siri.cfg->default_db_path,                                      \
-            (int) qp_dbname.len,                                            \
-            qp_dbname.via.raw);                                             \
-                                                                            \
-    if (stat(dbpath, &st) != -1)                                            \
-    {                                                                       \
-        snprintf(                                                           \
-                err_msg,                                                    \
-                SIRI_MAX_SIZE_ERR_MSG,                                      \
-                "database directory already exists: %s",                    \
-                dbpath);                                                    \
-        return CPROTO_ERR_ADMIN;                                            \
-    }                                                                       \
-                                                                            \
-    if (mkdir(dbpath, 0700) == -1)                                          \
-    {                                                                       \
-        snprintf(                                                           \
-                err_msg,                                                    \
-                SIRI_MAX_SIZE_ERR_MSG,                                      \
-                "cannot create directory: %s",                              \
-                dbpath);                                                    \
-        return CPROTO_ERR_ADMIN;                                            \
-    }                                                                       \
-                                                                            \
-    char dbfn[dbpath_len + max_filename_sz];                                \
-    sprintf(dbfn, "%s%s", dbpath, DB_CONF_FN);                              \
-                                                                            \
-    fp = fopen(dbfn, "w");                                                  \
-    if (fp == NULL)                                                         \
-    {                                                                       \
-        siri_admin_request_rollback(dbpath);                                \
-        snprintf(                                                           \
-                err_msg,                                                    \
-                SIRI_MAX_SIZE_ERR_MSG,                                      \
-                "cannot open file for writing: %s",                         \
-                dbfn);                                                      \
-        return CPROTO_ERR_ADMIN;                                            \
-    }                                                                       \
-                                                                            \
-    rc = fputs(DEFAULT_CONF, fp);                                           \
-                                                                            \
-    if (fclose(fp) || rc < 0)                                               \
-    {                                                                       \
-        siri_admin_request_rollback(dbpath);                                \
-        snprintf(                                                           \
-                err_msg,                                                    \
-                SIRI_MAX_SIZE_ERR_MSG,                                      \
-                "cannot write file: %s",                                    \
-                dbfn);                                                      \
-        return CPROTO_ERR_ADMIN;                                            \
-    }
-
-static cproto_server_t ADMIN_on_new_account(
-        qp_unpacker_t * qp_unpacker,
-        char * err_msg);
-static cproto_server_t ADMIN_on_change_password(
-        qp_unpacker_t * qp_unpacker,
-        char * err_msg);
-static cproto_server_t ADMIN_on_drop_account(
-        qp_unpacker_t * qp_unpacker,
-        qp_obj_t * qp_account,
-        char * err_msg);
-static cproto_server_t ADMIN_on_new_database(
-        qp_unpacker_t * qp_unpacker,
-        char * err_msg);
-static cproto_server_t ADMIN_on_new_replica_or_pool(
-        qp_unpacker_t * qp_unpacker,
-        uint16_t pid,
-        sirinet_stream_t * client,
-        int req,
-        char * err_msg);
-static cproto_server_t ADMIN_on_get_version(
-        qp_unpacker_t * qp_unpacker,
-        qp_packer_t ** packaddr,
-        char * err_msg);
-static cproto_server_t ADMIN_on_get_accounts(
-        qp_unpacker_t * qp_unpacker,
-        qp_packer_t ** packaddr,
-        char * err_msg);
-static cproto_server_t ADMIN_on_get_databases(
-        qp_unpacker_t * qp_unpacker,
-        qp_packer_t ** packaddr,
-        char * err_msg);
-static int8_t ADMIN_time_precision(qp_obj_t * qp_time_precision);
-static int64_t ADMIN_duration(qp_obj_t * qp_duration, uint8_t time_precision);
-static int ADMIN_list_databases(siridb_t * siridb, qp_packer_t * packer);
-static int ADMIN_find_database(siridb_t * siridb, qp_obj_t * dbname);
-static int ADMIN_list_accounts(
-        siri_admin_account_t * account,
-        qp_packer_t * packer);
-
-static size_t max_filename_sz;
-
-/*
- * Initialize administrative requests. (called once when initializing SiriDB)
- */
-int siri_admin_request_init(void)
-{
-    max_filename_sz = xmath_max_size(
-            3,
-            strlen(DB_CONF_FN),
-            strlen(DB_DAT_FN),
-            strlen(REINDEX_FN));
-
-    int pcre_error_num;
-    PCRE2_SIZE pcre_error_offset;
-
-    pcre2_code * regex;
-    pcre2_match_data * match_data;
-
-    regex = pcre2_compile(
-                (PCRE2_SPTR8) "^[a-zA-Z][a-zA-Z0-9-_]{0,18}[a-zA-Z0-9]$",
-                PCRE2_ZERO_TERMINATED,
-                0,
-                &pcre_error_num,
-                &pcre_error_offset,
-                NULL);
-    if (regex == NULL)
-    {
-        return -1;
-    }
-    match_data = pcre2_match_data_create_from_pattern(regex, NULL);
-
-    if(match_data == NULL)
-    {
-        pcre2_match_data_free(match_data);
-        pcre2_code_free(regex);
-        return -1;
-    }
-
-    siri.dbname_regex = regex;
-    siri.dbname_match_data = match_data;
-
-    return 0;
-}
-
-/*
- * Destroy administrative requests. (only called when exiting SiriDB)
- */
-void siri_admin_request_destroy(void)
-{
-    pcre2_match_data_free(siri.dbname_match_data);
-    pcre2_code_free(siri.dbname_regex);
-}
-
-/*
- * Returns CPROTO_ACK_ADMIN or CPROTO_DEFERRED when successful.
- * In case of an error CPROTO_ERR_ADMIN can be returned in which case err_msg
- * is set, or CPROTO_ERR_ADMIN_INVALID_REQUEST is returned.
- */
-cproto_server_t siri_admin_request(
-        int tp,
-        qp_unpacker_t * qp_unpacker,
-        qp_obj_t * qp_account,
-        qp_packer_t ** packaddr,
-        uint16_t pid,
-        sirinet_stream_t * client,
-        char * err_msg)
-{
-    switch ((admin_request_t) tp)
-    {
-    case ADMIN_NEW_ACCOUNT_:
-        return ADMIN_on_new_account(qp_unpacker, err_msg);
-    case ADMIN_CHANGE_PASSWORD_:
-        return ADMIN_on_change_password(qp_unpacker, err_msg);
-    case ADMIN_DROP_ACCOUNT_:
-        return ADMIN_on_drop_account(qp_unpacker, qp_account, err_msg);
-    case ADMIN_NEW_DATABASE_:
-        return ADMIN_on_new_database(qp_unpacker, err_msg);
-    case ADMIN_NEW_POOL:
-        return ADMIN_on_new_replica_or_pool(
-                qp_unpacker,
-                pid,
-                client,
-                ADMIN_NEW_POOL,
-                err_msg);
-    case ADMIN_NEW_REPLICA:
-        return ADMIN_on_new_replica_or_pool(
-                qp_unpacker,
-                pid,
-                client,
-                ADMIN_NEW_REPLICA,
-                err_msg);
-    case ADMIN_GET_VERSION:
-        return ADMIN_on_get_version(qp_unpacker, packaddr, err_msg);
-    case ADMIN_GET_ACCOUNTS:
-        return ADMIN_on_get_accounts(qp_unpacker, packaddr, err_msg);
-    case ADMIN_GET_DATABASES:
-        return ADMIN_on_get_databases(qp_unpacker, packaddr, err_msg);
-    default:
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-}
-
-/*
- * Returns CPROTO_ACK_ADMIN when successful.
- * In case of an error CPROTO_ERR_ADMIN can be returned in which case err_msg
- * is set, or CPROTO_ERR_ADMIN_INVALID_REQUEST is returned.
- */
-static cproto_server_t ADMIN_on_new_account(
-        qp_unpacker_t * qp_unpacker,
-        char * err_msg)
-{
-    qp_obj_t qp_key, qp_account, qp_password;
-
-    qp_account.tp = QP_HOOK;
-    qp_password.tp = QP_HOOK;
-
-    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "account",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_account) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "password",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_password) == QP_RAW)
-        {
-            continue;
-        }
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_account.tp == QP_HOOK || qp_password.tp == QP_HOOK)
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    return (siri_admin_account_new(
-            &siri,
-            &qp_account,
-            &qp_password,
-            0,
-            err_msg) ||
-            siri_admin_account_save(&siri, err_msg)) ?
-                    CPROTO_ERR_ADMIN : CPROTO_ACK_ADMIN;
-}
-
-/*
- * Returns CPROTO_ACK_ADMIN when successful.
- * In case of an error CPROTO_ERR_ADMIN can be returned in which case err_msg
- * is set, or CPROTO_ERR_ADMIN_INVALID_REQUEST is returned.
- */
-static cproto_server_t ADMIN_on_change_password(
-        qp_unpacker_t * qp_unpacker,
-        char * err_msg)
-{
-    qp_obj_t qp_key, qp_account, qp_password;
-
-    qp_account.tp = QP_HOOK;
-    qp_password.tp = QP_HOOK;
-
-    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "account",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_account) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "password",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_password) == QP_RAW)
-        {
-            continue;
-        }
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_account.tp == QP_HOOK || qp_password.tp == QP_HOOK)
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    return (siri_admin_account_change_password(
-            &siri,
-            &qp_account,
-            &qp_password,
-            err_msg) ||
-            siri_admin_account_save(&siri, err_msg)) ?
-                    CPROTO_ERR_ADMIN : CPROTO_ACK_ADMIN;
-}
-
-/*
- * Returns CPROTO_ACK_ADMIN when successful.
- * In case of an error CPROTO_ERR_ADMIN can be returned in which case err_msg
- * is set, or CPROTO_ERR_ADMIN_INVALID_REQUEST is returned.
- */
-static cproto_server_t ADMIN_on_drop_account(
-        qp_unpacker_t * qp_unpacker,
-        qp_obj_t * qp_account,
-        char * err_msg)
-{
-    qp_obj_t qp_key, qp_target;
-
-    qp_target.tp = QP_HOOK;
-
-    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "account",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_target) == QP_RAW)
-        {
-            continue;
-        }
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_target.tp == QP_HOOK)
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_target.len == qp_account->len &&
-        strncmp(
-            (const char *) qp_target.via.raw,
-            (const char *) qp_account->via.raw,
-            qp_target.len) == 0)
-    {
-        sprintf(err_msg, "cannot drop your own account");
-        return CPROTO_ERR_ADMIN;
-    }
-
-    return (siri_admin_account_drop(
-            &siri,
-            &qp_target,
-            err_msg) ||
-            siri_admin_account_save(&siri, err_msg)) ?
-                    CPROTO_ERR_ADMIN : CPROTO_ACK_ADMIN;
-}
-
-/*
- * Returns CPROTO_ACK_ADMIN when successful.
- * In case of an error CPROTO_ERR_ADMIN can be returned in which case err_msg
- * is set, or CPROTO_ERR_ADMIN_INVALID_REQUEST is returned.
- */
-static cproto_server_t ADMIN_on_new_database(
-        qp_unpacker_t * qp_unpacker,
-        char * err_msg)
-{
-    FILE * fp;
-    qp_obj_t
-        qp_key,
-        qp_dbname,
-        qp_time_precision,
-        qp_buffer_size,
-        qp_duration_num,
-        qp_duration_log;
-    size_t dbpath_len;
-    int pcre_exec_ret;
-    int rc;
-    struct stat st;
-    int8_t time_precision;
-    int64_t buffer_size, duration_num, duration_log;
-    siridb_t * siridb;
-    uuid_t uuid;
-
-    memset(&st, 0, sizeof(struct stat));
-
-    if (siri.siridb_list->len == MAX_NUMBER_DB)
-    {
-        sprintf(err_msg,
-                "maximum number of databases is reached (%zd)",
-                siri.siridb_list->len);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    qp_dbname.tp = QP_HOOK;
-    qp_time_precision.tp = QP_HOOK;
-    qp_buffer_size.tp = QP_HOOK;
-    qp_duration_num.tp = QP_HOOK;
-    qp_duration_log.tp = QP_HOOK;
-
-    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "dbname",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_dbname) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "time_precision",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_time_precision) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "buffer_size",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_buffer_size) == QP_INT64)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "duration_num",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_duration_num) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "duration_log",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_duration_log) == QP_RAW)
-        {
-            continue;
-        }
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_dbname.tp == QP_HOOK)
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    time_precision = (qp_time_precision.tp == QP_HOOK) ?
-            DEFAULT_TIME_PRECISION : ADMIN_time_precision(&qp_time_precision);
-    if (time_precision == -1)
-    {
-        snprintf(
-                err_msg,
-                SIRI_MAX_SIZE_ERR_MSG,
-                "invalid time precision: '%.*s' (expecting s, ms, us or ns)",
-                (int) qp_time_precision.len,
-                qp_time_precision.via.raw);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    duration_num = (qp_duration_num.tp == QP_HOOK) ?
-            DEFAULT_DURATION_NUM * xmath_ipow(1000, time_precision):
-            ADMIN_duration(&qp_duration_num, time_precision);
-
-    if (duration_num == -1)
-    {
-        snprintf(
-                err_msg,
-                SIRI_MAX_SIZE_ERR_MSG,
-                "invalid number duration: '%.*s' "
-                "(valid examples: 6h, 2d or 1w)",
-                (int) qp_duration_num.len,
-                qp_duration_num.via.raw);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    duration_log = (qp_duration_log.tp == QP_HOOK) ?
-            DEFAULT_DURATION_LOG * xmath_ipow(1000, time_precision):
-            ADMIN_duration(&qp_duration_log, time_precision);
-
-    if (duration_log == -1)
-    {
-        snprintf(
-                err_msg,
-                SIRI_MAX_SIZE_ERR_MSG,
-                "invalid log duration: '%.*s' "
-                "(valid examples: 6h, 2d or 1w)",
-                (int) qp_duration_log.len,
-                qp_duration_log.via.raw);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    buffer_size = (qp_buffer_size.tp == QP_HOOK) ?
-            DEFAULT_BUFFER_SIZE : qp_buffer_size.via.int64;
-
-    if (!siridb_buffer_is_valid_size(buffer_size))
-    {
-        sprintf(err_msg,
-                "invalid buffer size: %" PRId64
-                " (expecting a multiple of 512 with a maximum of %" PRId64 ")",
-                buffer_size,
-                (int64_t) MAX_BUFFER_SZ);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    CHECK_DBNAME_AND_CREATE_PATH
-
-    sprintf(dbfn, "%s%s", dbpath, DB_DAT_FN);
-    fp = qp_open(dbfn, "w");
-    if (fp == NULL)
-    {
-        siri_admin_request_rollback(dbpath);
-        snprintf(
-                err_msg,
-                SIRI_MAX_SIZE_ERR_MSG,
-                "cannot open file for writing: %s",
-                dbfn);
-        return CPROTO_ERR_ADMIN;
-    }
-    rc = 0;
-    uuid_generate(uuid);
-
-    if (qp_fadd_type(fp, QP_ARRAY_OPEN) ||
-        qp_fadd_int8(fp, SIRIDB_SCHEMA) ||
-        qp_fadd_raw(fp, (const unsigned char *) uuid, 16) ||
-        qp_fadd_raw(fp, qp_dbname.via.raw, qp_dbname.len) ||
-        qp_fadd_int8(fp, time_precision) ||
-        qp_fadd_int64(fp, buffer_size) ||
-        qp_fadd_int64(fp, duration_num) ||
-        qp_fadd_int64(fp, duration_log) ||
-        qp_fadd_string(fp, "NAIVE") ||
-        qp_fadd_double(fp, DEF_DROP_THRESHOLD) ||
-        qp_fadd_int64(fp, DEF_SELECT_POINTS_LIMIT) ||
-        qp_fadd_int64(fp, DEF_LIST_LIMIT) ||
-        qp_fadd_type(fp, QP_ARRAY_CLOSE))
-    {
-        rc = -1;
-    }
-
-    if (qp_close(fp) || rc == -1)
-    {
-        siri_admin_request_rollback(dbpath);
-        snprintf(
-                err_msg,
-                SIRI_MAX_SIZE_ERR_MSG,
-                "cannot write file: %s",
-                dbfn);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    siridb = siridb_new(dbpath, LOCK_QUIT_IF_EXIST);
-    if (siridb == NULL)
-    {
-        siri_admin_request_rollback(dbpath);
-        sprintf(err_msg, "error loading database");
-        return CPROTO_ERR_ADMIN;
-    }
-
-    siridb->server->flags |= SERVER_FLAG_RUNNING;
-
-    /* Force one heart-beat */
-    siri_heartbeat_force();
-
-    return CPROTO_ACK_ADMIN;
-}
-
-/*
- * Returns CPROTO_DEFERRED when successful.
- * In case of an error CPROTO_ERR_ADMIN can be returned in which case err_msg
- * is set, or CPROTO_ERR_ADMIN_INVALID_REQUEST is returned.
- */
-static cproto_server_t ADMIN_on_new_replica_or_pool(
-        qp_unpacker_t * qp_unpacker,
-        uint16_t pid,
-        sirinet_stream_t * client,
-        int req,
-        char * err_msg)
-{
-    FILE * fp;
-    qp_obj_t
-        qp_key,
-        qp_dbname,
-        qp_pool,
-        qp_host,
-        qp_port,
-        qp_username,
-        qp_password;
-    size_t dbpath_len;
-    int pcre_exec_ret;
-    int rc;
-    struct stat st;
-    uint16_t port;
-    uuid_t uuid;
-
-    memset(&st, 0, sizeof(struct stat));
-
-    if (siri.siridb_list->len == MAX_NUMBER_DB)
-    {
-        sprintf(err_msg,
-                "maximum number of databases is reached (%zd)",
-                siri.siridb_list->len);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    qp_dbname.tp = QP_HOOK;
-    qp_pool.tp = QP_HOOK;
-    qp_host.tp = QP_HOOK;
-    qp_port.tp = QP_HOOK;
-    qp_username.tp = QP_HOOK;
-    qp_password.tp = QP_HOOK;
-
-    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
-    {
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "dbname",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_dbname) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw, "pool", qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_pool) == QP_INT64)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw, "host", qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_host) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw, "port", qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_port) == QP_INT64)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "username",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_username) == QP_RAW)
-        {
-            continue;
-        }
-        if (    strncmp(
-                    (const char *) qp_key.via.raw,
-                    "password",
-                    qp_key.len) == 0 &&
-                qp_next(qp_unpacker, &qp_password) == QP_RAW)
-        {
-            continue;
-        }
-
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_dbname.tp == QP_HOOK ||
-        (
-            (req == ADMIN_NEW_POOL && qp_pool.tp != QP_HOOK) ||
-            (req == ADMIN_NEW_REPLICA && qp_pool.tp == QP_HOOK)
-        ) ||
-        qp_host.tp == QP_HOOK ||
-        qp_port.tp == QP_HOOK ||
-        qp_username.tp == QP_HOOK ||
-        qp_password.tp == QP_HOOK)
-    {
-        return CPROTO_ERR_ADMIN_INVALID_REQUEST;
-    }
-
-    if (qp_port.via.int64 < 1 || qp_port.via.int64 > 65535)
-    {
-        sprintf(err_msg,
-                "invalid port number: %" PRId64
-                " (expecting a value between 0 and 65536)",
-                qp_port.via.int64);
-        return CPROTO_ERR_ADMIN;
-    }
-
-    port = (uint16_t) qp_port.via.int64;
-    uuid_generate(uuid);
-
-    CHECK_DBNAME_AND_CREATE_PATH
-
-    if (req == ADMIN_NEW_POOL)
-    {
-        sprintf(dbfn, "%s%s", dbpath, REINDEX_FN);
-        fp = fopen(dbfn, "w");
-        if (fp == NULL || fclose(fp))
-        {
-            siri_admin_request_rollback(dbpath);
-            snprintf(
-                    err_msg,
-                    SIRI_MAX_SIZE_ERR_MSG,
-                    "cannot open file for writing: %s",
-                    dbfn);
-            return CPROTO_ERR_ADMIN;
-        }
-    }
-
-    if (siri_admin_client_request(
-            pid,
-            port,
-            /* -1 = new pool  */
-            (req == ADMIN_NEW_POOL) ? -1 : qp_pool.via.int64,
-            &uuid,
-            &qp_host,
-            &qp_username,
-            &qp_password,
-            &qp_dbname,
-            dbpath,
-            client,
-            err_msg))
-    {
-        siri_admin_request_rollback(dbpath);
-        return CPROTO_ERR_ADMIN;
-    }
-    return CPROTO_DEFERRED;
-}
-
-/*
- * Returns CPROTO_ACK_ADMIN_DATA when successful.
- * In case of an error CPROTO_ERR_ADMIN will be returned and err_msg is set
- */
-static cproto_server_t ADMIN_on_get_version(
-        qp_unpacker_t * qp_unpacker __attribute__((unused)),
-        qp_packer_t ** packaddr,
-        char * err_msg)
-{
-    qp_packer_t * packer = sirinet_packer_new(128);
-    if (packer != NULL)
-    {
-        if (!qp_add_type(packer, QP_ARRAY_OPEN) &&
-            !qp_add_string(packer, SIRIDB_VERSION))
-        {
-            *packaddr = packer;
-            return CPROTO_ACK_ADMIN_DATA;
-        }
-
-        /* error, free packer */
-        qp_packer_free(packer);
-    }
-    sprintf(err_msg, "memory allocation error");
-    return CPROTO_ERR_ADMIN;
-}
-
-static cproto_server_t ADMIN_on_get_accounts(
-        qp_unpacker_t * qp_unpacker __attribute__((unused)),
-        qp_packer_t ** packaddr,
-        char * err_msg)
-{
-    qp_packer_t * packer = sirinet_packer_new(128);
-
-    if (packer != NULL)
-    {
-        qp_add_type(packer, QP_ARRAY_OPEN);
-
-        if (!llist_walk(
-                siri.accounts,
-                (llist_cb) ADMIN_list_accounts,
-                packer))
-        {
-            *packaddr = packer;
-            return CPROTO_ACK_ADMIN_DATA;
-        }
-
-        /* error, free packer */
-        qp_packer_free(packer);
-    }
-    sprintf(err_msg, "memory allocation error");
-    return CPROTO_ERR_ADMIN;
-}
-
-static cproto_server_t ADMIN_on_get_databases(
-        qp_unpacker_t * qp_unpacker __attribute__((unused)),
-        qp_packer_t ** packaddr,
-        char * err_msg)
-{
-    qp_packer_t * packer = sirinet_packer_new(128);
-
-    if (packer != NULL)
-    {
-        qp_add_type(packer, QP_ARRAY_OPEN);
-
-        if (!llist_walk(
-                siri.siridb_list,
-                (llist_cb) ADMIN_list_databases,
-                packer))
-        {
-            *packaddr = packer;
-            return CPROTO_ACK_ADMIN_DATA;
-        }
-
-        /* error, free packer */
-        qp_packer_free(packer);
-    }
-    sprintf(err_msg, "memory allocation error");
-    return CPROTO_ERR_ADMIN;
-}
-
-void siri_admin_request_rollback(const char * dbpath)
-{
-    size_t dbpath_len = strlen(dbpath);
-    char dbfn[dbpath_len + max_filename_sz];
-
-    sprintf(dbfn, "%s%s", dbpath, DB_CONF_FN);
-    unlink(dbfn);
-    sprintf(dbfn, "%s%s", dbpath, DB_DAT_FN);
-    unlink(dbfn);
-    sprintf(dbfn, "%s%s", dbpath, REINDEX_FN);
-    unlink(dbfn);
-    if (rmdir(dbpath))
-    {
-        log_error("Roll-back creating new database has failed.");
-    }
-}
-
-static int8_t ADMIN_time_precision(qp_obj_t * qp_time_precision)
-{
-    if (qp_time_precision->tp != QP_RAW)
-    {
-        return -1;
-    }
-    if (qp_time_precision->len == 1 && qp_time_precision->via.raw[0] == 's')
-    {
-        return 0;
-    }
-    else if (qp_time_precision->len == 2 && qp_time_precision->via.raw[1] == 's')
-    {
-        switch (qp_time_precision->via.raw[0])
-        {
-        case 'm': return 1;
-        case 'u': return 2;
-        case 'n': return 3;
-        }
-    }
-    return -1;
-}
-
-static int64_t ADMIN_duration(qp_obj_t * qp_duration, uint8_t time_precision)
-{
-    char * endptr;
-    long int val;
-
-    if (qp_duration->tp != QP_RAW || qp_duration->len < 2)
-    {
-        return -1;
-    }
-
-    val = strtol((const char *) qp_duration->via.raw, &endptr, 10);
-
-    if (val < 1 || val > 99 || endptr == (const char *) qp_duration->via.raw)
-    {
-        return -1;
-    }
-
-    if (endptr != (const char *) qp_duration->via.raw + (qp_duration->len - 1))
-    {
-        return -1;
-    }
-
-    switch (*endptr)
-    {
-    case 'h': return xmath_ipow(1000, time_precision) * val * 3600;
-    case 'd': return xmath_ipow(1000, time_precision) * val * 86400;
-    case 'w': return xmath_ipow(1000, time_precision) * val * 604800;
-    }
-
-    return -1;
-}
-
-static int ADMIN_list_databases(siridb_t * siridb, qp_packer_t * packer)
-{
-    return qp_add_string(packer, siridb->dbname);
-}
-
-static int ADMIN_find_database(siridb_t * siridb, qp_obj_t * dbname)
-{
-    return (
-        strlen(siridb->dbname) == dbname->len &&
-        strncmp(
-            siridb->dbname,
-            (const char *) dbname->via.raw,
-            dbname->len) == 0);
-}
-
-static int ADMIN_list_accounts(
-        siri_admin_account_t * account,
-        qp_packer_t * packer)
-{
-    return qp_add_string(packer, account->account);
-}
index e668257eaf75da55c55fb561c7fb29159bc72b58..8f9a6a32c714d66eb602873ca955dcd3c5ba45f4 100644 (file)
@@ -1,3 +1,6 @@
+/*
+ * args.c - Parse SiriDB command line arguments.
+ */
 #include <siri/args/args.h>
 #include <argparse/argparse.h>
 #include <siri/version.h>
index d3d396a0b00ec90b756373b064d9c22fa147b5b5..3b5b9f1bff4c036e7d2115cb7130dc9fdf97349c 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * async.c - SiriDB async wrapper
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 21-07-2016
- *
+ * async.c - SiriDB async wrapper.
  */
 #include <logger/logger.h>
 #include <siri/async.h>
index 2ee9c723297a918042452c5cd1fbc4f56c22ab87..91517c2352833d176e79d431754dd6a0436da813 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * backup.c - Set SiriDB in backup mode.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 27-09-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
@@ -214,7 +206,7 @@ static void BACKUP_walk(siridb_t * siridb, void * args __attribute__((unused)))
          * A lock is not needed since the optimize thread is paused and this
          * is running from the main thread.
          */
-        slist_t * shard_list = imap_2slist(siridb->shards);
+        vec_t * shard_list = imap_2vec(siridb->shards);
 
         if (shard_list == NULL)
         {
@@ -237,6 +229,6 @@ static void BACKUP_walk(siridb_t * siridb, void * args __attribute__((unused)))
             }
         }
 
-        slist_free(shard_list);
+        vec_free(shard_list);
     }
 }
index 07d5fa0dde801fb67f8e0415d579144dbaa493e9..e40b89d39a3376e70a1d98d26c56a8b7e34b824b 100644 (file)
@@ -1,10 +1,5 @@
 /*
  * buffersync.c - Buffer sync.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2018, Transceptor Technology
- *
  */
 #include <logger/logger.h>
 #include <siri/db/server.h>
index 520d9349f91e81f6ad19de2b2580ff730ca420f2..581b9779d0b074e3091ef88f349a420045420a9c 100644 (file)
@@ -1,3 +1,6 @@
+/*
+ * cfg.h - Read the global SiriDB configuration file. (usually siridb.conf)
+ */
 #include <cfgparser/cfgparser.h>
 #include <inttypes.h>
 #include <limits.h>
@@ -5,7 +8,7 @@
 #include <siri/cfg/cfg.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/resource.h>
@@ -651,9 +654,9 @@ static void SIRI_CFG_read_address_port(
 
         if (    !strlen(address) ||
                 strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS ||
-                !strx_is_int(port) ||
+                !xstr_is_int(port) ||
                 strcpy(address_pt, address) == NULL ||
-                strx_replace_str(
+                xstr_replace_str(
                         address_pt,
                         "%HOSTNAME",
                         hostname,
index cc00dacf9ebfee0e51a82384c705c66c37d5ed6a..8cc862c2be6883a0ffed37422071ae52f13fd0f6 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * access.c - Access constants and functions.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-03-2016
- *
  */
 #include <siri/db/access.h>
 #include <stdio.h>
index ddb3bb8e7068ee07f7e23240fe53fb575ed88c7b..5ea3ed1cd51a54c06c25139c85bb25d1368d4e11 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * aggregate.c - SiriDB aggregation methods.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 15-04-2016
- *
  */
 #include <assert.h>
 #include <limits.h>
 #include <siri/db/variance.h>
 #include <siri/grammar/grammar.h>
 #include <siri/db/re.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <stddef.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <math.h>
 
 #define AGGR_NEW                                    \
 if ((aggr = AGGREGATE_new(gid)) == NULL)            \
 {                                                   \
     sprintf(err_msg, "Memory allocation error.");   \
-    siridb_aggregate_list_free(slist);              \
+    siridb_aggregate_list_free(vec);              \
     return NULL;                                    \
 }
 
-#define SLIST_APPEND                                \
-if (slist_append_safe(&slist, aggr))                \
+#define VEC_APPEND                                \
+if (vec_append_safe(&vec, aggr))                \
 {                                                   \
     sprintf(err_msg, "Memory allocation error.");   \
     AGGREGATE_free(aggr);                           \
-    siridb_aggregate_list_free(slist);              \
+    siridb_aggregate_list_free(vec);              \
     return NULL;                                    \
 }
 
@@ -204,12 +196,12 @@ void siridb_init_aggregates(void)
 /*
  * Returns NULL in case an error has occurred and the err_msg will be set.
  */
-slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
+vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
 {
     uint32_t gid;
     siridb_aggr_t * aggr;
-    slist_t * slist = slist_new(SLIST_DEFAULT_SIZE);
-    if (slist == NULL)
+    vec_t * vec = vec_new(VEC_DEFAULT_SIZE);
+    if (vec == NULL)
     {
         sprintf(err_msg, "Memory allocation error.");
         return NULL;
@@ -233,7 +225,7 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                             "Limit must be an integer value "
                             "larger than zero.");
                     AGGREGATE_free(aggr);
-                    siridb_aggregate_list_free(slist);
+                    siridb_aggregate_list_free(vec);
                     return NULL;
                 }
 
@@ -303,7 +295,7 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                 }
             }
 
-            SLIST_APPEND
+            VEC_APPEND
 
             break;
 
@@ -332,12 +324,12 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                 if (AGGREGATE_init_filter(aggr, onode, err_msg))
                 {
                     AGGREGATE_free(aggr);
-                    siridb_aggregate_list_free(slist);
+                    siridb_aggregate_list_free(vec);
                     return NULL;  /* err_msg is set */
                 }
             }
 
-            SLIST_APPEND
+            VEC_APPEND
 
             break;
 
@@ -359,7 +351,7 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                                 "Time-span must be an integer value "
                                 "larger than zero.");
                         AGGREGATE_free(aggr);
-                        siridb_aggregate_list_free(slist);
+                        siridb_aggregate_list_free(vec);
                         return NULL;
                     }
 
@@ -375,7 +367,7 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                                     "Group by time must be an integer "
                                     "value larger than zero.");
                             AGGREGATE_free(aggr);
-                            siridb_aggregate_list_free(slist);
+                            siridb_aggregate_list_free(vec);
                             return NULL;
                         }
 
@@ -384,7 +376,7 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                 }
             }
 
-            SLIST_APPEND
+            VEC_APPEND
 
             break;
 
@@ -417,12 +409,12 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
                             "Group by time must be an integer value "
                             "larger than zero.");
                     AGGREGATE_free(aggr);
-                    siridb_aggregate_list_free(slist);
+                    siridb_aggregate_list_free(vec);
                     return NULL;
                 }
             }
 
-            SLIST_APPEND
+            VEC_APPEND
 
             break;
 
@@ -447,13 +439,13 @@ slist_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg)
         children = children->next->next;
     }
 
-    return slist;
+    return vec;
 }
 
 /*
  * Destroy aggregates list. (parsing NULL is not allowed)
  */
-void siridb_aggregate_list_free(slist_t * alist)
+void siridb_aggregate_list_free(vec_t * alist)
 {
     size_t i;
     for (i = 0; i < alist->len; i++)
@@ -591,7 +583,7 @@ static int AGGREGATE_init_filter(
 
     case CLERI_GID_R_FLOAT:
         aggr->filter_tp = TP_DOUBLE;
-        aggr->filter_via.real = strx_to_double(node->str, node->len);
+        aggr->filter_via.real = xstr_to_double(node->str, node->len);
         break;
 
     case CLERI_GID_STRING:
@@ -602,7 +594,7 @@ static int AGGREGATE_init_filter(
             sprintf(err_msg, "Memory allocation error.");
             return -1;
         }
-        strx_extract_string(
+        xstr_extract_string(
                 (char *) aggr->filter_via.raw, node->str, node->len);
         return 0;
 
index 749a35b76149309ddc9842bc2b912183996d8959..5a72c5f16397da5ced91876a820be0fa30d25cac 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * auth.c - Handle SiriDB authentication.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
index dc860bc3e882341502d7e25e558cf172d963f252..97156d1644030691a0b0b06cb637aa49e1b52e17 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * buffer.c - Buffer for integer and double series.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 01-04-2016
- *
+ * buffer.c - Buffer for integer and double values.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
@@ -52,7 +44,7 @@ siridb_buffer_t * siridb_buffer_new(void)
     {
         return NULL;
     }
-    buffer->empty = slist_new(SLIST_DEFAULT_SIZE);
+    buffer->empty = vec_new(VEC_DEFAULT_SIZE);
     if (buffer->empty == NULL)
     {
         free(buffer);
@@ -77,7 +69,7 @@ void siridb_buffer_free(siridb_buffer_t * buffer)
     }
     free(buffer->template);
     free(buffer->path);
-    slist_free(buffer->empty);
+    vec_free(buffer->empty);
     free(buffer);
 }
 
@@ -443,7 +435,7 @@ static int buffer__use_empty(
         siridb_buffer_t * buffer,
         siridb_series_t * series)
 {
-    series->bf_offset = (long int) slist_pop(buffer->empty);
+    series->bf_offset = (long int) vec_pop(buffer->empty);
 
     if (siridb_buffer_write_empty(buffer, series))
     {
@@ -507,7 +499,7 @@ static int buffer__create_new(
 
     while ((buffer_pos -= buffer->size) > series->bf_offset)
     {
-        slist_append_safe(&buffer->empty, (void *) buffer_pos);
+        vec_append_safe(&buffer->empty, (void *) buffer_pos);
     }
 
     return 0;
index f7832b92f21b3a6c1290a17494d7e7241eea07a2..deaebb063e01b8f914e614c4f069d3b4cfa0e61b 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * db.c - contains functions  and constants for a SiriDB database.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * db.c - SiriDB database.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
@@ -34,7 +26,7 @@
 #include <string.h>
 #include <uuid/uuid.h>
 #include <xpath/xpath.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <timeit/timeit.h>
 
 /*
@@ -228,9 +220,9 @@ siridb_t * siridb_new(const char * dbpath, int lock_flags)
     log_info("Updating series properties");
 
     /* create a copy since 'siridb_series_update_props' might drop a series */
-    slist_t * slist = imap_2slist(siridb->series_map);
+    vec_t * vec = imap_2vec(siridb->series_map);
 
-    if (slist == NULL)
+    if (vec == NULL)
     {
         log_error("Could update series properties for database '%s'",
                 siridb->dbname);
@@ -238,12 +230,12 @@ siridb_t * siridb_new(const char * dbpath, int lock_flags)
         return NULL;
     }
 
-    for (i = 0; i < slist->len; i++)
+    for (i = 0; i < vec->len; i++)
     {
-        siridb_series_update_props(siridb, (siridb_series_t * )slist->data[i]);
+        siridb_series_update_props(siridb, (siridb_series_t * )vec->data[i]);
     }
 
-    slist_free(slist);
+    vec_free(vec);
 
     /* generate pools, this can raise a signal */
     log_info("Initialize pools");
index 853a3372230b55e7ec3256a6f368415315bbf7f2..cff654385e1b82b49757f95ab24484ffa80f1ae2 100644 (file)
@@ -1,14 +1,5 @@
 /*
  * ffile.c - FIFO file.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 30-06-2016
- *
- *
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
index cd8b200db24ee5032792ff667cc26db09e554634..e6c069021ac3ee0f54b8634074617b053fda6b49 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * fifo.c - First in, first out file buffer .
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 30-06-2016
- *
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
index 03f5ba272e87f1c167e54a6fc95c8f46586a1182..c63706cdc56ca061b35449709a40646e4d23130f 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * forward.c - Handle forwarding series while re-indexing
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 31-07-2016
- *
+ * forward.c - Handle forwarding series while re-indexing.
  */
 #include <qpack/qpack.h>
 #include <siri/async.h>
@@ -17,7 +9,7 @@
 #include <siri/net/protocol.h>
 #include <stddef.h>
 
-static void FORWARD_on_response(slist_t * promises, uv_async_t * handle);
+static void FORWARD_on_response(vec_t * promises, uv_async_t * handle);
 static void FORWARD_free(uv_handle_t * handle);
 
 /*
@@ -168,7 +160,7 @@ void siridb_forward_points_to_pools(uv_async_t * handle)
  *
  * This function can raise a SIGNAL.
  */
-static void FORWARD_on_response(slist_t * promises, uv_async_t * handle)
+static void FORWARD_on_response(vec_t * promises, uv_async_t * handle)
 {
     if (promises != NULL)
     {
index 085a074a3e5f295a122eb8d1e25ee6d0f495c554..92256cce61f7c2abcdbf99a69893d2fc25ebf62f 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * group.c - Group (saved regular expressions).
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-08-2016
- *
  */
 #include <assert.h>
 #include <siri/db/db.h>
@@ -16,9 +8,9 @@
 #include <siri/db/series.h>
 #include <siri/err.h>
 #include <siri/grammar/grammar.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <stdlib.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 
 #define SIRIDB_MIN_GROUP_LEN 1
 #define SIRIDB_MAX_GROUP_LEN 255
@@ -46,7 +38,7 @@ siridb_group_t * siridb_group_new(
         group->flags = GROUP_FLAG_INIT;
         group->name = NULL;
         group->source = strndup(source, source_len);
-        group->series = slist_new(SLIST_DEFAULT_SIZE);
+        group->series = vec_new(VEC_DEFAULT_SIZE);
         group->regex = NULL;
         group->match_data = NULL;
 
@@ -187,7 +179,7 @@ void siridb_group_cleanup(siridb_group_t * group)
 
     group->series->len -= dropped;
 
-    slist_compact(&group->series);
+    vec_compact(&group->series);
 }
 
 /*
@@ -207,7 +199,7 @@ int siridb_group_test_series(siridb_group_t * group, siridb_series_t * series)
 
     if (rc >= 0)
     {
-        if (slist_append_safe(&group->series, series))
+        if (vec_append_safe(&group->series, series))
         {
             log_critical(
                     "Cannot append series '%s' to group '%s'",
@@ -281,13 +273,13 @@ int siridb_group_update_expression(
 
     group->series->len = 0;
 
-    slist_compact(&group->series);
+    vec_compact(&group->series);
 
     if (~group->flags & GROUP_FLAG_INIT)
     {
         group->flags |= GROUP_FLAG_INIT;
 
-        if (slist_append_safe(&groups->ngroups, group))
+        if (vec_append_safe(&groups->ngroups, group))
         {
             /* we log critical since allocation errors are critical, this does
              * however not influence the running SiriDB in is not critical in that
@@ -370,7 +362,7 @@ void siridb__group_free(siridb_group_t * group)
             series = (siridb_series_t *) group->series->data[i];
             siridb_series_decref(series);
         }
-        slist_free(group->series);
+        vec_free(group->series);
     }
 
     pcre2_code_free(group->regex);
index f417abc5f8880964cf1613f2b0c71aedec8eb48b..1a9ad0f8fb8967759eae970983064e1eb61a9950 100644 (file)
@@ -1,13 +1,6 @@
 /*
  * groups.c - Groups (saved regular expressions).
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-08-2016
- *
  * Info groups->mutex:
  *
  *  Main thread:
@@ -40,7 +33,7 @@
 #include <siri/err.h>
 #include <siri/net/protocol.h>
 #include <siri/siri.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <xpath/xpath.h>
@@ -61,7 +54,7 @@ static void GROUPS_loop_finish(uv_work_t * work, int status);
 static int GROUPS_write(siridb_group_t * group, qp_fpacker_t * fpacker);
 static void GROUPS_init_groups(siridb_t * siridb);
 static void GROUPS_init_series(siridb_t * siridb);
-static int GROUPS_2slist(siridb_group_t * group, slist_t * groups_list);
+static int GROUPS_2vec(siridb_group_t * group, vec_t * groups_list);
 static void GROUPS_cleanup(siridb_groups_t * groups);
 /*
  * In case of an error the return value is NULL and a SIGNAL is raised.
@@ -81,8 +74,8 @@ siridb_groups_t * siridb_groups_new(siridb_t * siridb)
         groups->ref = 2;  /* for the main thread and for the groups thread  */
         groups->fn = NULL;
         groups->groups = ct_new();
-        groups->nseries = slist_new(SLIST_DEFAULT_SIZE);
-        groups->ngroups = slist_new(SLIST_DEFAULT_SIZE);
+        groups->nseries = vec_new(VEC_DEFAULT_SIZE);
+        groups->ngroups = vec_new(VEC_DEFAULT_SIZE);
         uv_mutex_init(&groups->mutex);
         groups->work.data = (siridb_t *) siridb;
 
@@ -136,7 +129,7 @@ int siridb_groups_add_series(
 
     uv_mutex_lock(&groups->mutex);
 
-    if (slist_append_safe(&groups->nseries, series) == 0)
+    if (vec_append_safe(&groups->nseries, series) == 0)
     {
         siridb_series_incref(series);
     }
@@ -201,7 +194,7 @@ int siridb_groups_add_group(
         break;
 
     case CT_OK:
-        if (slist_append_safe(&groups->ngroups, group))
+        if (vec_append_safe(&groups->ngroups, group))
         {
             siridb_group_decref(group);
             sprintf(err_msg, "Memory allocation error.");
@@ -387,7 +380,7 @@ static void GROUPS_free(siridb_groups_t * groups)
             series = (siridb_series_t *) groups->nseries->data[i];
             siridb_series_decref(series);
         }
-        slist_free(groups->nseries);
+        vec_free(groups->nseries);
     }
 
     if (groups->groups != NULL)
@@ -403,7 +396,7 @@ static void GROUPS_free(siridb_groups_t * groups)
             group = (siridb_group_t *) groups->ngroups->data[i];
             siridb_group_decref(group);
         }
-        slist_free(groups->ngroups);
+        vec_free(groups->ngroups);
     }
 
     uv_mutex_destroy(&groups->mutex);
@@ -414,10 +407,10 @@ static void GROUPS_free(siridb_groups_t * groups)
 /*
  * Group thread.
  */
-static int GROUPS_2slist(siridb_group_t * group, slist_t * groups_list)
+static int GROUPS_2vec(siridb_group_t * group, vec_t * groups_list)
 {
     siridb_group_incref(group);
-    slist_append(groups_list, group);
+    vec_append(groups_list, group);
     return 0;
 }
 
@@ -561,7 +554,7 @@ static void GROUPS_init_series(siridb_t * siridb)
 
     while (groups->nseries->len)
     {
-        series = (siridb_series_t *) slist_pop(groups->nseries);
+        series = (siridb_series_t *) vec_pop(groups->nseries);
 
         if (~series->flags & SIRIDB_SERIES_IS_DROPPED)
         {
@@ -596,7 +589,7 @@ static void GROUPS_init_groups(siridb_t * siridb)
 {
     siridb_groups_t * groups = siridb->groups;
     siridb_group_t * group;
-    slist_t * series_list;
+    vec_t * series_list;
     siridb_series_t * series;
     size_t i;
 
@@ -606,7 +599,7 @@ static void GROUPS_init_groups(siridb_t * siridb)
     uv_mutex_lock(&siridb->series_mutex);
 
     series_list = (groups->nseries->len) ?
-            NULL : imap_2slist_ref(siridb->series_map);
+            NULL : imap_2vec_ref(siridb->series_map);
 
     uv_mutex_unlock(&siridb->series_mutex);
 
@@ -620,7 +613,7 @@ static void GROUPS_init_groups(siridb_t * siridb)
 
     while (groups->ngroups->len)
     {
-        group = (siridb_group_t *) slist_pop(groups->ngroups);
+        group = (siridb_group_t *) vec_pop(groups->ngroups);
 
         /* we must be sure this group is empty */
         assert (group->series->len == 0);
@@ -664,7 +657,7 @@ static void GROUPS_init_groups(siridb_t * siridb)
         siridb_series_decref(series);
     }
 
-    slist_free(series_list);
+    vec_free(series_list);
 }
 
 /*
@@ -676,11 +669,11 @@ static void GROUPS_cleanup(siridb_groups_t * groups)
 
     groups->flags &= ~GROUPS_FLAG_DROPPED_SERIES;
 
-    slist_t * groups_list = slist_new(groups->groups->len);
+    vec_t * groups_list = vec_new(groups->groups->len);
 
     if (groups_list != NULL)
     {
-        ct_values(groups->groups, (ct_val_cb) GROUPS_2slist, groups_list);
+        ct_values(groups->groups, (ct_val_cb) GROUPS_2vec, groups_list);
     }
 
     uv_mutex_unlock(&groups->mutex);
@@ -696,7 +689,7 @@ static void GROUPS_cleanup(siridb_groups_t * groups)
 
     while (groups_list->len)
     {
-        group = (siridb_group_t *) slist_pop(groups_list);
+        group = (siridb_group_t *) vec_pop(groups_list);
 
         if (!group->flags)
         {
@@ -712,5 +705,5 @@ static void GROUPS_cleanup(siridb_groups_t * groups)
         usleep(10000);  /* 10ms  */
     }
 
-    slist_free(groups_list);
+    vec_free(groups_list);
 }
index 8392d6eabe15dc1dcecdb6ea6d7fd6faffec4f03..4dd9e60432a8ef37a845693f0eada41bd91ed4d8 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * initsync.c - Initial replica synchronization
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 22-07-2016
- *
+ * initsync.c - Initial replica synchronization.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
index 2615839a6ddd5260f10bae37062e9d1bd65889c5..6c9c4551a3d156a0ff023fe9a96a82311cd0488e 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * insert.c - Handler database inserts.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 24-03-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
@@ -47,7 +39,7 @@ if (*ts > series->end)              \
 
 static void INSERT_free(uv_handle_t * handle);
 static void INSERT_points_to_pools(uv_async_t * handle);
-static void INSERT_on_response(slist_t * promises, uv_async_t * handle);
+static void INSERT_on_response(vec_t * promises, uv_async_t * handle);
 static uint16_t INSERT_get_pool(siridb_t * siridb, qp_obj_t * qp_series_name);
 
 static void INSERT_local_free_cb(uv_async_t * handle);
@@ -366,7 +358,7 @@ int insert_init_backend_local(
  *
  * This function can raise a SIGNAL.
  */
-static void INSERT_on_response(slist_t * promises, uv_async_t * handle)
+static void INSERT_on_response(vec_t * promises, uv_async_t * handle)
 {
     if (promises != NULL)
     {
@@ -972,7 +964,7 @@ static void INSERT_local_promise_cb(
             NULL);
     sirinet_promises_t * promises = (sirinet_promises_t *) promise->data;
     promise->data = pkg;
-    slist_append(promises->promises, (void *) promise);
+    vec_append(promises->promises, (void *) promise);
 
     SIRINET_PROMISES_CHECK(promises)
 }
index 98b0c8edda3212ce4570865755116fc13abed247..b3aacaeb5888d4127adf58d295d8ecd01db04151 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * listener.c - contains functions for processing queries.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * listener.c - Contains functions for processing queries.
  */
 #include <assert.h>
 #include <cexpr/cexpr.h>
@@ -39,7 +31,7 @@
 #include <siri/net/protocol.h>
 #include <siri/net/clserver.h>
 #include <siri/siri.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <sys/time.h>
 
 
@@ -273,14 +265,14 @@ static void on_ack_response(
         sirinet_promise_t * promise,
         sirinet_pkg_t * pkg,
         int status);
-static void on_alter_xxx_response(slist_t * promises, uv_async_t * handle);
-static void on_count_xxx_response(slist_t * promises, uv_async_t * handle);
-static void on_drop_series_response(slist_t * promises, uv_async_t * handle);
-static void on_drop_shards_response(slist_t * promises, uv_async_t * handle);
-static void on_groups_response(slist_t * promises, uv_async_t * handle);
-static void on_list_xxx_response(slist_t * promises, uv_async_t * handle);
-static void on_select_response(slist_t * promises, uv_async_t * handle);
-static void on_update_xxx_response(slist_t * promises, uv_async_t * handle);
+static void on_alter_xxx_response(vec_t * promises, uv_async_t * handle);
+static void on_count_xxx_response(vec_t * promises, uv_async_t * handle);
+static void on_drop_series_response(vec_t * promises, uv_async_t * handle);
+static void on_drop_shards_response(vec_t * promises, uv_async_t * handle);
+static void on_groups_response(vec_t * promises, uv_async_t * handle);
+static void on_list_xxx_response(vec_t * promises, uv_async_t * handle);
+static void on_select_response(vec_t * promises, uv_async_t * handle);
+static void on_update_xxx_response(vec_t * promises, uv_async_t * handle);
 
 /* helper functions */
 static void master_select_work(uv_work_t * handle);
@@ -293,7 +285,7 @@ static int items_select_master(
 static int items_select_master_merge(
         const char * name,
         size_t len,
-        slist_t * plist,
+        vec_t * plist,
         uv_async_t * handle);
 static int items_select_other(
         const char * name,
@@ -303,7 +295,7 @@ static int items_select_other(
 static int items_select_other_merge(
         const char * name,
         size_t len,
-        slist_t * plist,
+        vec_t * plist,
         uv_async_t * handle);
 static void on_select_unpack_points(
         qp_unpacker_t * unpacker,
@@ -522,7 +514,7 @@ static void enter_alter_group(uv_async_t * handle)
     siridb_group_t * group;
 
     char name[group_node->len - 1];
-    strx_extract_string(name, group_node->str, group_node->len);
+    xstr_extract_string(name, group_node->str, group_node->len);
 
     if ((group = ct_get(siridb->groups->groups, name)) == NULL)
     {
@@ -615,7 +607,7 @@ static void enter_alter_user(uv_async_t * handle)
     siridb_user_t * user;
 
     char name[user_node->len - 1];
-    strx_extract_string(name, user_node->str, user_node->len);
+    xstr_extract_string(name, user_node->str, user_node->len);
 
     if ((user = siridb_users_get_user(siridb, name, NULL)) == NULL)
     {
@@ -742,7 +734,7 @@ static void enter_grant_user(uv_async_t * handle)
                 query->nodes->node->children->next->node;
     siridb_user_t * user;
     char username[user_node->len - 1];
-    strx_extract_string(username, user_node->str, user_node->len);
+    xstr_extract_string(username, user_node->str, user_node->len);
 
     if ((user = siridb_users_get_user(siridb, username, NULL)) == NULL)
     {
@@ -787,7 +779,7 @@ static void enter_group_match(uv_async_t * handle)
     char group_name[node->len - 1];
 
     /* extract series name */
-    strx_extract_string(group_name, node->str, node->len);
+    xstr_extract_string(group_name, node->str, node->len);
 
     siridb_group_t * group =
             (siridb_group_t *) ct_get(siridb->groups->groups, group_name);
@@ -857,7 +849,7 @@ static void enter_help(uv_async_t * handle)
 
     query->free_cb = (uv_close_cb) query_help_free;
 
-    strx_split_join(query->data, ' ', '_');
+    xstr_split_join(query->data, ' ', '_');
 
     SIRIPARSER_ASYNC_NEXT_NODE
 }
@@ -931,7 +923,7 @@ static void enter_merge_as(uv_async_t * handle)
         MEM_ERR_RET
     }
 
-    strx_extract_string(q_select->merge_as, node->str, node->len);
+    xstr_extract_string(q_select->merge_as, node->str, node->len);
 
     if (IS_MASTER && query->nodes->node->children->next->next->next != NULL)
     {
@@ -962,7 +954,7 @@ static void enter_revoke_user(uv_async_t * handle)
                 query->nodes->node->children->next->node;
     siridb_user_t * user;
     char username[user_node->len - 1];
-    strx_extract_string(username, user_node->str, user_node->len);
+    xstr_extract_string(username, user_node->str, user_node->len);
 
     if ((user = siridb_users_get_user(siridb, username, NULL)) == NULL)
     {
@@ -1096,7 +1088,7 @@ static void enter_set_name(uv_async_t * handle)
                 query->nodes->node->children->next->next->node;
 
     char name[name_node->len - 1];
-    strx_extract_string(name, name_node->str, name_node->len);
+    xstr_extract_string(name, name_node->str, name_node->len);
 
     query_alter_t * q_alter = (query_alter_t *) query->data;
     switch (q_alter->alter_tp)
@@ -1142,7 +1134,7 @@ static void enter_set_password(uv_async_t * handle)
             query->nodes->node->children->next->next->node;
 
     char password[pw_node->len - 1];
-    strx_extract_string(password, pw_node->str, pw_node->len);
+    xstr_extract_string(password, pw_node->str, pw_node->len);
 
     if (siridb_user_set_password(user, password, query->err_msg))
     {
@@ -1165,7 +1157,7 @@ static void enter_series_name(uv_async_t * handle)
     char series_name[node->len - 1];
 
     /* extract series name */
-    strx_extract_string(series_name, node->str, node->len);
+    xstr_extract_string(series_name, node->str, node->len);
 
     if (siridb_is_reindexing(siridb))
     {
@@ -1328,7 +1320,7 @@ static void enter_series_all(uv_async_t * handle)
 
     uv_mutex_lock(&siridb->series_mutex);
 
-    q_wrapper->slist = imap_2slist_ref(
+    q_wrapper->vec = imap_2vec_ref(
             (   q_wrapper->update_cb == NULL ||
                 q_wrapper->update_cb == &imap_union_ref ||
                 q_wrapper->update_cb == &imap_symmetric_difference_ref) ?
@@ -1339,25 +1331,25 @@ static void enter_series_all(uv_async_t * handle)
     q_wrapper->series_tmp = (q_wrapper->update_cb == NULL) ?
             q_wrapper->series_map : imap_new();
 
-    if (q_wrapper->slist == NULL || q_wrapper->series_tmp == NULL)
+    if (q_wrapper->vec == NULL || q_wrapper->series_tmp == NULL)
     {
         MEM_ERR_RET
     }
 
-    for (q_wrapper->slist_index = 0;
-         q_wrapper->slist_index < q_wrapper->slist->len;
-         ++q_wrapper->slist_index)
+    for (q_wrapper->vec_index = 0;
+         q_wrapper->vec_index < q_wrapper->vec->len;
+         ++q_wrapper->vec_index)
     {
-        series = q_wrapper->slist->data[q_wrapper->slist_index];
+        series = q_wrapper->vec->data[q_wrapper->vec_index];
         if (imap_add(q_wrapper->series_tmp, series->id, series))
         {
             MEM_ERR_RET
         }
     }
 
-    slist_free(q_wrapper->slist);
-    q_wrapper->slist = NULL;
-    q_wrapper->slist_index = 0;
+    vec_free(q_wrapper->vec);
+    q_wrapper->vec = NULL;
+    q_wrapper->vec_index = 0;
 
     if (q_wrapper->update_cb != NULL)
     {
@@ -1399,7 +1391,7 @@ static void enter_series_re(uv_async_t * handle)
     {
         uv_mutex_lock(&siridb->series_mutex);
 
-        q_wrapper->slist = imap_2slist_ref(
+        q_wrapper->vec = imap_2vec_ref(
                 (   q_wrapper->update_cb == NULL ||
                     q_wrapper->update_cb == &imap_union_ref ||
                     q_wrapper->update_cb == &imap_symmetric_difference_ref) ?
@@ -1410,7 +1402,7 @@ static void enter_series_re(uv_async_t * handle)
         q_wrapper->series_tmp = (q_wrapper->update_cb == NULL) ?
                 q_wrapper->series_map : imap_new();
 
-        if (q_wrapper->slist == NULL || q_wrapper->series_tmp == NULL)
+        if (q_wrapper->vec == NULL || q_wrapper->series_tmp == NULL)
         {
             MEM_ERR_RET
         }
@@ -1504,7 +1496,7 @@ static void enter_xxx_columns(uv_async_t * handle)
     cleri_children_t * columns = query->nodes->node->children;
     query_list_t * qlist = (query_list_t *) query->data;
 
-    qlist->props = slist_new(DEFAULT_ALLOC_COLUMNS);
+    qlist->props = vec_new(DEFAULT_ALLOC_COLUMNS);
 
     if (qlist->props == NULL)
     {
@@ -1518,7 +1510,7 @@ static void enter_xxx_columns(uv_async_t * handle)
                 (const unsigned char *) columns->node->str,
                 columns->node->len);
 
-        if (slist_append_safe(
+        if (vec_append_safe(
                 &qlist->props,
                 &columns->node->children->node->cl_obj->gid))
         {
@@ -1786,13 +1778,13 @@ static void exit_count_series(uv_async_t * handle)
     {
         uv_mutex_lock(&siridb->series_mutex);
 
-        q_count->slist = imap_2slist_ref(
+        q_count->vec = imap_2vec_ref(
                 (q_count->series_map == NULL) ?
                         siridb->series_map : q_count->series_map);
 
         uv_mutex_unlock(&siridb->series_mutex);
 
-        if (q_count->slist == NULL)
+        if (q_count->vec == NULL)
         {
             MEM_ERR_RET
         }
@@ -1829,28 +1821,28 @@ static void exit_count_series_length(uv_async_t * handle)
     if (q_count->where_expr == NULL)
     {
         size_t i;
-        slist_t * slist;
+        vec_t * vec;
         siridb_series_t * series;
 
         uv_mutex_lock(&siridb->series_mutex);
 
-        slist = imap_2slist((q_count->series_map == NULL) ?
+        vec = imap_2vec((q_count->series_map == NULL) ?
                 siridb->series_map : q_count->series_map);
 
         uv_mutex_unlock(&siridb->series_mutex);
 
-        if (slist == NULL)
+        if (vec == NULL)
         {
             MEM_ERR_RET
         }
 
-        for (i = 0; i < slist->len; i++)
+        for (i = 0; i < vec->len; i++)
         {
-            series = (siridb_series_t *) slist->data[i];
+            series = (siridb_series_t *) vec->data[i];
             q_count->n += series->length;
         }
 
-        slist_free(slist);
+        vec_free(vec);
 
         if (IS_MASTER)
         {
@@ -1873,13 +1865,13 @@ static void exit_count_series_length(uv_async_t * handle)
 
         uv_mutex_lock(&siridb->series_mutex);
 
-        q_count->slist = imap_2slist_ref(
+        q_count->vec = imap_2vec_ref(
                 (q_count->series_map == NULL) ?
                         siridb->series_map : q_count->series_map);
 
         uv_mutex_unlock(&siridb->series_mutex);
 
-        if (q_count->slist == NULL)
+        if (q_count->vec == NULL)
         {
             MEM_ERR_RET
         }
@@ -2046,11 +2038,11 @@ static void exit_count_shards(uv_async_t * handle)
                 .server=siridb->server
         };
         size_t i;
-        slist_t * shards_list;
+        vec_t * shards_list;
 
         uv_mutex_lock(&siridb->shards_mutex);
 
-        shards_list = imap_2slist_ref(siridb->shards);
+        shards_list = imap_2vec_ref(siridb->shards);
 
         uv_mutex_unlock(&siridb->shards_mutex);
 
@@ -2080,7 +2072,7 @@ static void exit_count_shards(uv_async_t * handle)
             siridb_shard_decref(vshard.shard);
         }
 
-        slist_free(shards_list);
+        vec_free(shards_list);
     }
 
     if (IS_MASTER)
@@ -2105,7 +2097,7 @@ static void exit_count_shards_size(uv_async_t * handle)
     query_count_t * q_count = (query_count_t *) query->data;
     uint64_t duration;
     size_t i;
-    slist_t * shards_list;
+    vec_t * shards_list;
     siridb_shard_view_t vshard = {
             .server=siridb->server
     };
@@ -2114,7 +2106,7 @@ static void exit_count_shards_size(uv_async_t * handle)
 
     uv_mutex_lock(&siridb->shards_mutex);
 
-    shards_list = imap_2slist_ref(siridb->shards);
+    shards_list = imap_2vec_ref(siridb->shards);
 
     uv_mutex_unlock(&siridb->shards_mutex);
 
@@ -2144,7 +2136,7 @@ static void exit_count_shards_size(uv_async_t * handle)
         siridb_shard_decref(vshard.shard);
     }
 
-    slist_free(shards_list);
+    vec_free(shards_list);
 
     if (IS_MASTER)
     {
@@ -2199,7 +2191,7 @@ static void exit_create_group(uv_async_t * handle)
     MASTER_CHECK_ACCESSIBLE(siridb)
 
     char group_name[name_nd->len - 1];
-    strx_extract_string(group_name, name_nd->str, name_nd->len);
+    xstr_extract_string(group_name, name_nd->str, name_nd->len);
 
     if (siridb_groups_add_group(
             siridb->groups,
@@ -2263,7 +2255,7 @@ static void exit_create_user(uv_async_t * handle)
     MASTER_CHECK_ACCESSIBLE(siridb)
 
     char name[user_node->len - 1];
-    strx_extract_string(name, user_node->str, user_node->len);
+    xstr_extract_string(name, user_node->str, user_node->len);
 
     if (siridb_user_set_name(
             siridb,
@@ -2324,7 +2316,7 @@ static void exit_drop_group(uv_async_t * handle)
 
     char name[group_node->len - 1];
 
-    strx_extract_string(name, group_node->str, group_node->len);
+    xstr_extract_string(name, group_node->str, group_node->len);
 
     if (siridb_groups_drop_group(siridb->groups, name, query->err_msg))
     {
@@ -2360,18 +2352,18 @@ static void exit_drop_series(uv_async_t * handle)
     MASTER_CHECK_ACCESSIBLE(siridb)
 
     /*
-     * We transform or copy the references from imap to slist because we need
+     * We transform or copy the references from imap to vec because we need
      * this list for both filtering or performing the actual drop.
      */
     uv_mutex_lock(&siridb->series_mutex);
 
-    q_drop->slist = (q_drop->series_map == NULL) ?
-        imap_2slist_ref(siridb->series_map) :
-        imap_slist_pop(q_drop->series_map);
+    q_drop->vec = (q_drop->series_map == NULL) ?
+        imap_2vec_ref(siridb->series_map) :
+        imap_vec_pop(q_drop->series_map);
 
     uv_mutex_unlock(&siridb->series_mutex);
 
-    if (q_drop->slist == NULL)
+    if (q_drop->vec == NULL)
     {
         MEM_ERR_RET
     }
@@ -2419,10 +2411,10 @@ static void exit_drop_series(uv_async_t * handle)
     else
     {
         double percent = (double)
-                q_drop->slist->len / siridb->series_map->len;
+                q_drop->vec->len / siridb->series_map->len;
 
         if (IS_MASTER &&
-            q_drop->slist->len &&
+            q_drop->vec->len &&
             (~q_drop->flags & QUERIES_IGNORE_DROP_THRESHOLD) &&
             percent >= siridb->drop_threshold)
         {
@@ -2440,7 +2432,7 @@ static void exit_drop_series(uv_async_t * handle)
         {
             QP_ADD_SUCCESS
 
-            q_drop->n = q_drop->slist->len;
+            q_drop->n = q_drop->vec->len;
 
             uv_async_t * next = (uv_async_t *) malloc(sizeof(uv_async_t));
 
@@ -2541,7 +2533,7 @@ static void exit_drop_shards(uv_async_t * handle)
 
     uv_mutex_lock(&siridb->shards_mutex);
 
-    q_drop->shards_list = imap_2slist_ref(siridb->shards);
+    q_drop->shards_list = imap_2vec_ref(siridb->shards);
 
     uv_mutex_unlock(&siridb->shards_mutex);
 
@@ -2643,7 +2635,7 @@ static void exit_drop_user(uv_async_t * handle)
             query->nodes->node->children->next->node;
     char username[user_node->len - 1];
 
-    strx_extract_string(username, user_node->str, user_node->len);
+    xstr_extract_string(username, user_node->str, user_node->len);
 
     if (siridb_users_drop_user(
             siridb,
@@ -2824,16 +2816,16 @@ static void exit_list_pools(uv_async_t * handle)
 
     if (q_list->props == NULL)
     {
-        q_list->props = slist_new(3);
+        q_list->props = vec_new(3);
 
         if (q_list->props == NULL)
         {
             MEM_ERR_RET
         }
 
-        slist_append(q_list->props, &GID_K_POOL);
-        slist_append(q_list->props, &GID_K_SERVERS);
-        slist_append(q_list->props, &GID_K_SERIES);
+        vec_append(q_list->props, &GID_K_POOL);
+        vec_append(q_list->props, &GID_K_SERVERS);
+        vec_append(q_list->props, &GID_K_SERIES);
         qp_add_raw(query->packer, (const unsigned char *) "pool", 4);
         qp_add_raw(query->packer, (const unsigned char *) "servers", 7);
         qp_add_raw(query->packer, (const unsigned char *) "series", 6);
@@ -2897,14 +2889,14 @@ static void exit_list_series(uv_async_t * handle)
 
     if (q_list->props == NULL)
     {
-        q_list->props = slist_new(1);
+        q_list->props = vec_new(1);
 
         if (q_list->props == NULL)
         {
             MEM_ERR_RET
         }
 
-        slist_append(q_list->props, &GID_K_NAME);
+        vec_append(q_list->props, &GID_K_NAME);
         qp_add_raw(query->packer, (const unsigned char *) "name", 4);
     }
 
@@ -2915,12 +2907,12 @@ static void exit_list_series(uv_async_t * handle)
 
     uv_mutex_lock(&siridb->series_mutex);
 
-    q_list->slist = imap_2slist_ref((q_list->series_map == NULL) ?
+    q_list->vec = imap_2vec_ref((q_list->series_map == NULL) ?
                     siridb->series_map : q_list->series_map);
 
     uv_mutex_unlock(&siridb->series_mutex);
 
-    if (q_list->slist == NULL)
+    if (q_list->vec == NULL)
     {
         MEM_ERR_RET;
     }
@@ -2975,18 +2967,18 @@ static void exit_list_servers(uv_async_t * handle)
 
     if (q_list->props == NULL)
     {
-        q_list->props = slist_new(5);
+        q_list->props = vec_new(5);
 
         if (q_list->props == NULL)
         {
             MEM_ERR_RET
         }
 
-        slist_append(q_list->props, &GID_K_NAME);
-        slist_append(q_list->props, &GID_K_POOL);
-        slist_append(q_list->props, &GID_K_VERSION);
-        slist_append(q_list->props, &GID_K_ONLINE);
-        slist_append(q_list->props, &GID_K_STATUS);
+        vec_append(q_list->props, &GID_K_NAME);
+        vec_append(q_list->props, &GID_K_POOL);
+        vec_append(q_list->props, &GID_K_VERSION);
+        vec_append(q_list->props, &GID_K_ONLINE);
+        vec_append(q_list->props, &GID_K_STATUS);
         qp_add_raw(query->packer, (const unsigned char *) "name", 4);
         qp_add_raw(query->packer, (const unsigned char *) "pool", 4);
         qp_add_raw(query->packer, (const unsigned char *) "version", 7);
@@ -3041,11 +3033,11 @@ static void exit_list_shards(uv_async_t * handle)
             .server=siridb->server
     };
     size_t i;
-    slist_t * shards_list;
+    vec_t * shards_list;
 
     uv_mutex_lock(&siridb->shards_mutex);
 
-    shards_list = imap_2slist_ref(siridb->shards);
+    shards_list = imap_2vec_ref(siridb->shards);
 
     uv_mutex_unlock(&siridb->shards_mutex);
 
@@ -3056,18 +3048,18 @@ static void exit_list_shards(uv_async_t * handle)
 
     if (q_list->props == NULL)
     {
-        q_list->props = slist_new(5);
+        q_list->props = vec_new(5);
 
         if (q_list->props == NULL)
         {
             MEM_ERR_RET
         }
 
-        slist_append(q_list->props, &GID_K_SID);
-        slist_append(q_list->props, &GID_K_POOL);
-        slist_append(q_list->props, &GID_K_SERVER);
-        slist_append(q_list->props, &GID_K_START);
-        slist_append(q_list->props, &GID_K_END);
+        vec_append(q_list->props, &GID_K_SID);
+        vec_append(q_list->props, &GID_K_POOL);
+        vec_append(q_list->props, &GID_K_SERVER);
+        vec_append(q_list->props, &GID_K_START);
+        vec_append(q_list->props, &GID_K_END);
         qp_add_raw(query->packer, (const unsigned char *) "sid", 3);
         qp_add_raw(query->packer, (const unsigned char *) "pool", 4);
         qp_add_raw(query->packer, (const unsigned char *) "server", 6);
@@ -3144,7 +3136,7 @@ static void exit_list_shards(uv_async_t * handle)
         siridb_shard_decref(vshard.shard);
     }
 
-    slist_free(shards_list);
+    vec_free(shards_list);
 
     if (IS_MASTER && q_list->limit)
     {
@@ -3169,7 +3161,7 @@ static void exit_list_users(uv_async_t * handle)
     siridb_t * siridb = query->client->siridb;
 
     llist_node_t * node = siridb->users->first;
-    slist_t * props = ((query_list_t *) query->data)->props;
+    vec_t * props = ((query_list_t *) query->data)->props;
     cexpr_cb_t cb = (cexpr_cb_t) siridb_user_cexpr_cb;
     query_list_t * q_list = (query_list_t *) query->data;
     cexpr_t * where_expr = q_list->where_expr;
@@ -3299,10 +3291,10 @@ static void exit_select_aggregate(uv_async_t * handle)
 
     if (q_select->where_expr != NULL)
     {
-        /* we transform the references from imap to slist */
-        q_select->slist = imap_slist_pop(q_select->series_map);
+        /* we transform the references from imap to vec */
+        q_select->vec = imap_vec_pop(q_select->series_map);
 
-        if (q_select->slist == NULL)
+        if (q_select->vec == NULL)
         {
             MEM_ERR_RET
         }
@@ -3357,7 +3349,7 @@ static void exit_select_aggregate(uv_async_t * handle)
         {
             if (q_select->merge_as != NULL)
             {
-                slist_t * plist = slist_new(SLIST_DEFAULT_SIZE);
+                vec_t * plist = vec_new(VEC_DEFAULT_SIZE);
 
                 if (plist == NULL || ct_add(
                         q_select->result,
@@ -3370,7 +3362,7 @@ static void exit_select_aggregate(uv_async_t * handle)
                     sprintf(query->err_msg,
                             "Error while merging points. Make sure the "
                             "destination series name is valid.");
-                    slist_free(plist);
+                    vec_free(plist);
                     siridb_query_send_error(handle, CPROTO_ERR_QUERY);
                     return;
                 }
@@ -3386,9 +3378,9 @@ static void exit_select_aggregate(uv_async_t * handle)
                     siridb_query_send_error(handle, CPROTO_ERR_QUERY);
                     return;
                 }
-                q_select->slist = imap_2slist_ref(q_select->series_map);
+                q_select->vec = imap_2vec_ref(q_select->series_map);
 
-                if (q_select->slist == NULL)
+                if (q_select->vec == NULL)
                 {
                     MEM_ERR_RET
                 }
@@ -3514,7 +3506,7 @@ static void exit_set_address(uv_async_t * handle)
     }
 
     char address[node->len - 1];
-    strx_extract_string(address, node->str, node->len);
+    xstr_extract_string(address, node->str, node->len);
 
     int rc;
     rc = siridb_server_update_address(siridb, server, address, server->port);
@@ -3651,7 +3643,7 @@ static void exit_set_drop_threshold(uv_async_t * handle)
 
     cleri_node_t * node = query->nodes->node->children->next->next->node;
 
-    double drop_threshold = strx_to_double(node->str, node->len);
+    double drop_threshold = xstr_to_double(node->str, node->len);
 
     if (drop_threshold < 0.0 || drop_threshold > 1.0)
     {
@@ -3713,7 +3705,7 @@ static void exit_set_list_limit(uv_async_t * handle)
 
     cleri_node_t * node = query->nodes->node->children->next->next->node;
 
-    uint64_t limit = strx_to_uint64(node->str, node->len);
+    uint64_t limit = xstr_to_uint64(node->str, node->len);
 
     if (limit < 1000 || limit >= 4294967296)
     {
@@ -3923,7 +3915,7 @@ static void exit_set_port(uv_async_t * handle)
     }
 
 
-    uint64_t port = strx_to_uint64(node->str, node->len);
+    uint64_t port = xstr_to_uint64(node->str, node->len);
 
     if (port > 65535)
     {
@@ -3971,7 +3963,7 @@ static void exit_set_select_points_limit(uv_async_t * handle)
 
     cleri_node_t * node = query->nodes->node->children->next->next->node;
 
-    uint64_t limit = strx_to_uint64(node->str, node->len);
+    uint64_t limit = xstr_to_uint64(node->str, node->len);
 
     if (limit < 1 || limit >= 4294967296)
     {
@@ -4033,7 +4025,7 @@ static void exit_set_timezone(uv_async_t * handle)
     MASTER_CHECK_ACCESSIBLE(siridb)
 
     char timezone[node->len - 1];
-    strx_extract_string(timezone, node->str, node->len);
+    xstr_extract_string(timezone, node->str, node->len);
 
     iso8601_tz_t new_tz = iso8601_tz(timezone);
 
@@ -4207,20 +4199,20 @@ static void async_count_series(uv_async_t * handle)
     query_count_t * q_count = (query_count_t *) query->data;
     uint8_t async_more = 0;
 
-    size_t index_end = q_count->slist_index + MAX_ITERATE_COUNT;
+    size_t index_end = q_count->vec_index + MAX_ITERATE_COUNT;
 
-    if (index_end >= q_count->slist->len)
+    if (index_end >= q_count->vec->len)
     {
-        index_end = q_count->slist->len;
+        index_end = q_count->vec->len;
     }
     else
     {
         async_more = 1;
     }
 
-    for (; q_count->slist_index < index_end; q_count->slist_index++)
+    for (; q_count->vec_index < index_end; q_count->vec_index++)
     {
-        series = (siridb_series_t *) q_count->slist->data[q_count->slist_index];
+        series = (siridb_series_t *) q_count->vec->data[q_count->vec_index];
         q_count->n += cexpr_run(
                     q_count->where_expr,
                     (cexpr_cb_t) siridb_series_cexpr_cb,
@@ -4255,20 +4247,20 @@ static void async_count_series_length(uv_async_t * handle)
     query_count_t * q_count = (query_count_t *) query->data;
     uint8_t async_more = 0;
 
-    size_t index_end = q_count->slist_index + MAX_ITERATE_COUNT;
+    size_t index_end = q_count->vec_index + MAX_ITERATE_COUNT;
 
-    if (index_end >= q_count->slist->len)
+    if (index_end >= q_count->vec->len)
     {
-        index_end = q_count->slist->len;
+        index_end = q_count->vec->len;
     }
     else
     {
         async_more = 1;
     }
 
-    for (; q_count->slist_index < index_end; q_count->slist_index++)
+    for (; q_count->vec_index < index_end; q_count->vec_index++)
     {
-        series = (siridb_series_t *) q_count->slist->data[q_count->slist_index];
+        series = (siridb_series_t *) q_count->vec->data[q_count->vec_index];
 
         if (cexpr_run(
                 q_count->where_expr,
@@ -4310,11 +4302,11 @@ static void async_drop_series(uv_async_t * handle)
     siridb_series_t * series;
     uint8_t async_more = 0;
 
-    size_t index_end = q_drop->slist_index + MAX_ITERATE_COUNT;
+    size_t index_end = q_drop->vec_index + MAX_ITERATE_COUNT;
 
-    if (index_end >= q_drop->slist->len)
+    if (index_end >= q_drop->vec->len)
     {
-        index_end = q_drop->slist->len;
+        index_end = q_drop->vec->len;
     }
     else
     {
@@ -4323,9 +4315,9 @@ static void async_drop_series(uv_async_t * handle)
 
     uv_mutex_lock(&siridb->series_mutex);
 
-    for (; q_drop->slist_index < index_end; q_drop->slist_index++)
+    for (; q_drop->vec_index < index_end; q_drop->vec_index++)
     {
-        series = (siridb_series_t *) q_drop->slist->data[q_drop->slist_index];
+        series = (siridb_series_t *) q_drop->vec->data[q_drop->vec_index];
         siridb_series_drop(siridb, series);
         siridb_series_decref(series);
     }
@@ -4333,7 +4325,7 @@ static void async_drop_series(uv_async_t * handle)
     uv_mutex_unlock(&siridb->series_mutex);
 
     /* flush dropped file change to disk */
-    if (q_drop->slist->len)
+    if (q_drop->vec->len)
     {
         siridb_series_flush_dropped(siridb);
     }
@@ -4366,7 +4358,7 @@ static void async_drop_shards(uv_async_t * handle)
 
     if (q_drop->shards_list->len)
     {
-        siridb_shard_t * shard = (siridb_shard_t *) slist_pop(
+        siridb_shard_t * shard = (siridb_shard_t *) vec_pop(
                 q_drop->shards_list);
 
         siridb_shard_drop(
@@ -4401,21 +4393,21 @@ static void async_filter_series(uv_async_t * handle)
     cexpr_t * where_expr = q_wrapper->where_expr;
     uint8_t async_more = 0;
     siridb_series_t * series;
-    size_t index_end = q_wrapper->slist_index + MAX_ITERATE_COUNT;
+    size_t index_end = q_wrapper->vec_index + MAX_ITERATE_COUNT;
 
-    if (index_end >= q_wrapper->slist->len)
+    if (index_end >= q_wrapper->vec->len)
     {
-        index_end = q_wrapper->slist->len;
+        index_end = q_wrapper->vec->len;
     }
     else
     {
         async_more = 1;
     }
 
-    for (; q_wrapper->slist_index < index_end; q_wrapper->slist_index++)
+    for (; q_wrapper->vec_index < index_end; q_wrapper->vec_index++)
     {
         series = (siridb_series_t *)
-                q_wrapper->slist->data[q_wrapper->slist_index];
+                q_wrapper->vec->data[q_wrapper->vec_index];
 
         if (cexpr_run(
                 where_expr,
@@ -4441,10 +4433,10 @@ static void async_filter_series(uv_async_t * handle)
     else
     {
         /* free the s-list object and reset index */
-        slist_free(q_wrapper->slist);
+        vec_free(q_wrapper->vec);
 
-        q_wrapper->slist = NULL;
-        q_wrapper->slist_index = 0;
+        q_wrapper->vec = NULL;
+        q_wrapper->vec_index = 0;
 
         /* cleanup where statement since we do not need it anymore */
         cexpr_free(q_wrapper->where_expr);
@@ -4470,26 +4462,26 @@ static void async_list_series(uv_async_t * handle)
 {
     siridb_query_t * query = (siridb_query_t *) handle->data;
     query_list_t * q_list = (query_list_t *) query->data;
-    slist_t * props = q_list->props;
+    vec_t * props = q_list->props;
     cexpr_t * where_expr = q_list->where_expr;
     uint8_t async_more = 0;
     siridb_series_t * series;
     size_t i;
-    size_t index_end = q_list->slist_index + MAX_ITERATE_COUNT;
+    size_t index_end = q_list->vec_index + MAX_ITERATE_COUNT;
 
-    if (index_end >= q_list->slist->len)
+    if (index_end >= q_list->vec->len)
     {
-        index_end = q_list->slist->len;
+        index_end = q_list->vec->len;
     }
     else
     {
         async_more = 1;
     }
 
-    for (;  q_list->limit && q_list->slist_index < index_end;
-            q_list->slist_index++)
+    for (;  q_list->limit && q_list->vec_index < index_end;
+            q_list->vec_index++)
     {
-        series = (siridb_series_t *) q_list->slist->data[q_list->slist_index];
+        series = (siridb_series_t *) q_list->vec->data[q_list->vec_index];
 
         if (where_expr == NULL || cexpr_run(
                     where_expr,
@@ -4569,8 +4561,8 @@ static void async_no_points_aggregate(uv_async_t * handle)
     siridb_points_t * aggr_points;
     int required_shard = 0;
 
-    for (;  q_select->slist_index < q_select->slist->len;
-            ++q_select->slist_index)
+    for (;  q_select->vec_index < q_select->vec->len;
+            ++q_select->vec_index)
     {
         if (required_shard > MAX_BATCH_REQUIRE_SHARD)
         {
@@ -4579,7 +4571,7 @@ static void async_no_points_aggregate(uv_async_t * handle)
         }
 
         series = (siridb_series_t *)
-                q_select->slist->data[q_select->slist_index];
+                q_select->vec->data[q_select->vec_index];
         /*
          * We must decrement the ref count immediately since the index is
          * incremented by one. The series will not be freed since at least
@@ -4657,18 +4649,18 @@ static void async_no_points_aggregate(uv_async_t * handle)
             }
             else
             {
-                slist_t ** plist;
+                vec_t ** plist;
 
                 name = siridb_presuf_name(
                         q_select->presuf,
                         q_select->merge_as,
                         strlen(q_select->merge_as));
 
-                plist = (slist_t **) ct_getaddr(q_select->result, name);
+                plist = (vec_t **) ct_getaddr(q_select->result, name);
 
                 if (    name == NULL ||
                         plist == NULL ||
-                        slist_append_safe(plist, points))
+                        vec_append_safe(plist, points))
                 {
                     sprintf(query->err_msg, "Error adding points to map.");
                     siridb_points_free(points);
@@ -4689,9 +4681,9 @@ static void async_no_points_aggregate(uv_async_t * handle)
         siridb_aggregate_list_free(q_select->alist);
         q_select->alist = NULL;
 
-        slist_free(q_select->slist);
-        q_select->slist = NULL;
-        q_select->slist_index = 0;
+        vec_free(q_select->vec);
+        q_select->vec = NULL;
+        q_select->vec_index = 0;
 
         SIRIPARSER_ASYNC_NEXT_NODE
     }
@@ -4722,7 +4714,7 @@ static void async_select_aggregate(uv_async_t * handle)
     }
 
     series = (siridb_series_t *)
-            q_select->slist->data[q_select->slist_index];
+            q_select->vec->data[q_select->vec_index];
 
     /*
      * We must decrement the ref count immediately since we now update the
@@ -4731,7 +4723,7 @@ static void async_select_aggregate(uv_async_t * handle)
      */
     siridb_series_decref(series);
 
-    if ((++q_select->slist_index) < q_select->slist->len)
+    if ((++q_select->vec_index) < q_select->vec->len)
     {
         async_more = 1;
     }
@@ -4816,18 +4808,18 @@ static void async_select_aggregate(uv_async_t * handle)
         }
         else
         {
-            slist_t ** plist;
+            vec_t ** plist;
 
             name = siridb_presuf_name(
                     q_select->presuf,
                     q_select->merge_as,
                     strlen(q_select->merge_as));
 
-            plist = (slist_t **) ct_getaddr(q_select->result, name);
+            plist = (vec_t **) ct_getaddr(q_select->result, name);
 
             if (    name == NULL ||
                     plist == NULL ||
-                    slist_append_safe(plist, points))
+                    vec_append_safe(plist, points))
             {
                 sprintf(query->err_msg, "Error adding points to map.");
                 siridb_points_free(points);
@@ -4847,9 +4839,9 @@ static void async_select_aggregate(uv_async_t * handle)
         siridb_aggregate_list_free(q_select->alist);
         q_select->alist = NULL;
 
-        slist_free(q_select->slist);
-        q_select->slist = NULL;
-        q_select->slist_index = 0;
+        vec_free(q_select->vec);
+        q_select->vec = NULL;
+        q_select->vec_index = 0;
 
         SIRIPARSER_ASYNC_NEXT_NODE
     }
@@ -4861,11 +4853,11 @@ static void async_series_re(uv_async_t * handle)
     query_wrapper_t * q_wrapper = (query_wrapper_t *) query->data;
     uint8_t async_more = 0;
     siridb_series_t * series;
-    size_t index_end = q_wrapper->slist_index + MAX_ITERATE_COUNT;
+    size_t index_end = q_wrapper->vec_index + MAX_ITERATE_COUNT;
 
-    if (index_end >= q_wrapper->slist->len)
+    if (index_end >= q_wrapper->vec->len)
     {
-        index_end = q_wrapper->slist->len;
+        index_end = q_wrapper->vec->len;
     }
     else
     {
@@ -4874,10 +4866,10 @@ static void async_series_re(uv_async_t * handle)
 
     int pcre_exec_ret;
 
-    for (; q_wrapper->slist_index < index_end; q_wrapper->slist_index++)
+    for (; q_wrapper->vec_index < index_end; q_wrapper->vec_index++)
     {
         series = (siridb_series_t *)
-                q_wrapper->slist->data[q_wrapper->slist_index];
+                q_wrapper->vec->data[q_wrapper->vec_index];
 
         pcre_exec_ret = pcre2_match(
                 q_wrapper->regex,
@@ -4901,7 +4893,7 @@ static void async_series_re(uv_async_t * handle)
     else
     {
         /* free the s-list object and reset index */
-        slist_free(q_wrapper->slist);
+        vec_free(q_wrapper->vec);
 
         pcre2_code_free(q_wrapper->regex);
         pcre2_match_data_free(q_wrapper->match_data);
@@ -4909,8 +4901,8 @@ static void async_series_re(uv_async_t * handle)
         q_wrapper->regex = NULL;
         q_wrapper->match_data = NULL;
 
-        q_wrapper->slist = NULL;
-        q_wrapper->slist_index = 0;
+        q_wrapper->vec = NULL;
+        q_wrapper->vec_index = 0;
 
         if (q_wrapper->update_cb != NULL)
         {
@@ -4990,7 +4982,7 @@ static void on_ack_response(
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_alter_xxx_response(slist_t * promises, uv_async_t * handle)
+static void on_alter_xxx_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5059,7 +5051,7 @@ static void on_alter_xxx_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_count_xxx_response(slist_t * promises, uv_async_t * handle)
+static void on_count_xxx_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5130,7 +5122,7 @@ static void on_count_xxx_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_drop_series_response(slist_t * promises, uv_async_t * handle)
+static void on_drop_series_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5186,7 +5178,7 @@ static void on_drop_series_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_drop_shards_response(slist_t * promises, uv_async_t * handle)
+static void on_drop_shards_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5242,7 +5234,7 @@ static void on_drop_shards_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_groups_response(slist_t * promises, uv_async_t * handle)
+static void on_groups_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5304,7 +5296,7 @@ static void on_groups_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_list_xxx_response(slist_t * promises, uv_async_t * handle)
+static void on_list_xxx_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5386,7 +5378,7 @@ static void on_list_xxx_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_select_response(slist_t * promises, uv_async_t * handle)
+static void on_select_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5562,7 +5554,7 @@ static void on_select_response(slist_t * promises, uv_async_t * handle)
  *
  * Make sure to run siri_async_incref() on the handle
  */
-static void on_update_xxx_response(slist_t * promises, uv_async_t * handle)
+static void on_update_xxx_response(vec_t * promises, uv_async_t * handle)
 {
     ON_PROMISES
 
@@ -5705,7 +5697,7 @@ static int items_select_master(
 static int items_select_master_merge(
         const char * name,
         size_t len,
-        slist_t * plist,
+        vec_t * plist,
         uv_async_t * handle)
 {
     siridb_query_t * query = (siridb_query_t *) handle->data;
@@ -5728,7 +5720,7 @@ static int items_select_master_merge(
         }
         break;
     case 1:
-        points = slist_pop(plist);
+        points = vec_pop(plist);
         break;
     default:
         points = siridb_points_merge(plist, query->err_msg);
@@ -5811,7 +5803,7 @@ static int items_select_other(
 static int items_select_other_merge(
         const char * name,
         size_t len,
-        slist_t * plist,
+        vec_t * plist,
         uv_async_t * handle)
 {
     size_t i;
@@ -5905,7 +5897,7 @@ static void on_select_unpack_merged_points(
             qp_is_raw_term(qp_name) &&
             qp_is_array(qp_next(unpacker, NULL)))
     {
-        slist_t ** plist = (slist_t **) ct_getaddr(
+        vec_t ** plist = (vec_t **) ct_getaddr(
                 q_select->result,
                 (const char *) qp_name->via.raw);
 
@@ -5944,7 +5936,7 @@ static void on_select_unpack_merged_points(
                     memcpy(points->data, qp_points->via.raw, qp_points->len);
                 }
 
-                if (slist_append_safe(plist, points))
+                if (vec_append_safe(plist, points))
                 {
                     siridb_points_free(points);
                 }
@@ -5964,7 +5956,7 @@ static int values_list_groups(siridb_group_t * group, uv_async_t * handle)
     siridb_query_t * query = (siridb_query_t *) handle->data;
     cexpr_t * where_expr = ((query_list_t *) query->data)->where_expr;
     cexpr_cb_t cb = (cexpr_cb_t) siridb_group_cexpr_cb;
-    slist_t * props = ((query_list_t *) query->data)->props;
+    vec_t * props = ((query_list_t *) query->data)->props;
 
     if (where_expr == NULL || cexpr_run(where_expr, cb, group))
     {
@@ -6005,12 +5997,12 @@ static void finish_list_groups(uv_async_t * handle)
 
     if (q_list->props == NULL)
     {
-        q_list->props = slist_new(1);
+        q_list->props = vec_new(1);
         if (q_list->props == NULL)
         {
             MEM_ERR_RET
         }
-        slist_append(q_list->props, &GID_K_NAME);
+        vec_append(q_list->props, &GID_K_NAME);
         qp_add_raw(query->packer, (const unsigned char *) "name", 4);
     }
 
index 5e0c421c8c9ccd407c15e2e5d5cae14383b1d391..54a59c9c638ce140c9a5fbbde2cdafa6c1be1549 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * lookup.c - SiriDB Pool lookup.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 29-07-2016
- *
+ * lookup.c - Find and assign to which pool series belong.
  */
 #include <siri/db/lookup.h>
 #include <siri/err.h>
index bac54eb04f254fc96668b257f3d47a1e7c16fada..a5da036b1500e09b314e01dc092e836473b84fcf 100644 (file)
@@ -1,16 +1,6 @@
 /*
  * median.c - Calculate median, median high and median low.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-04-2016
- *
  */
-
-
 #include <siri/db/median.h>
 #include <siri/db/points.h>
 #include <stdbool.h>
index 8c756e138d89dfd6f1aded57effcc2f8d3f82c9e..a7bd8a3f2a482f590ddb2b2b49d998ea03601325 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * misc.c - Miscellaneous functions used by SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-08-2016
- *
  */
 #include <siri/db/misc.h>
 #include <stdlib.h>
index 0cebd471467c618ab1fba1616b6a60e8ceffb56f..49e56ac115d3e438fc349fec4cc28ee975ef4d5f 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * node.c - contains logic for cleri nodes which we need to parse.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * nodes.c - Contains logic for cleri nodes which we need to parse.
  */
 #include <logger/logger.h>
 #include <siri/db/nodes.h>
index 79e0d2661945ed646fc394b761a2edb285311e1d..fe99bca56c3098363a66e47c96e4166fe120b828 100644 (file)
@@ -1,15 +1,6 @@
 /*
- * pcache.h - Points structure with notion or its size
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-10-2016
- *
+ * pcache.c - Points structure with notion of its size.
  */
-
 #include <assert.h>
 #include <siri/db/pcache.h>
 #include <siri/err.h>
index 7edcf5bbff54c5005b7abb024389b08bcb038a71..682e6d323171bd40111a4d6ff3e7dc099ec90405 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * points.c - Array object for points.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-04-2016
- *
  */
 #include <siri/db/points.h>
 #include <logger/logger.h>
@@ -17,7 +9,7 @@
 #include <siri/err.h>
 #include <unistd.h>
 #include <string.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 
 #define MAX_ITERATE_MERGE_COUNT 1000
 #define POINTS_MAX_QSORT 250000
@@ -37,11 +29,11 @@ static void POINTS_unzip_raw(
         uint64_t * start_ts,
         uint64_t * end_ts,
         uint8_t has_overlap);
-static void POINTS_sort_while_merge(slist_t * plist, siridb_points_t * points);
-static void POINTS_merge_and_sort(slist_t * plist, siridb_points_t * points);
+static void POINTS_sort_while_merge(vec_t * plist, siridb_points_t * points);
+static void POINTS_merge_and_sort(vec_t * plist, siridb_points_t * points);
 static void POINTS_simple_sort(siridb_points_t * points);
 static inline int POINTS_compare(const void * a, const void * b);
-static void POINTS_highest_and_merge(slist_t * plist, siridb_points_t * points);
+static void POINTS_highest_and_merge(vec_t * plist, siridb_points_t * points);
 static size_t POINTS_strlen_check_ascii(const char * str, uint8_t * is_ascii);
 static void POINTS_output_literal(
         size_t len,
@@ -289,7 +281,7 @@ int siridb_points_raw_pack(siridb_points_t * points, qp_packer_t * packer)
  * (err_msg is set when an error has occurred)
  * Use this function only when having at least two 'series' in the list.
  */
-siridb_points_t * siridb_points_merge(slist_t * plist, char * err_msg)
+siridb_points_t * siridb_points_merge(vec_t * plist, char * err_msg)
 {
     assert (plist->len >= 2);
     siridb_points_t * points;
@@ -348,7 +340,7 @@ siridb_points_t * siridb_points_merge(slist_t * plist, char * err_msg)
          * list length to 0. We do have to restore the points length since
          * this is decremented by one.
          */
-        points = (siridb_points_t *) slist_pop(plist);
+        points = (siridb_points_t *) vec_pop(plist);
         points->len++;
         return points;
     }
@@ -1158,7 +1150,7 @@ int siridb_points_unzip_string_raw(
     {
         size_t slen;
         points->data[points->len].ts = *tpt;
-        points->data[points->len].val.str = strx_dup(cpt, &slen);
+        points->data[points->len].val.str = xstr_dup(cpt, &slen);
         cpt += slen + 1;
     }
     return 0;
@@ -1344,7 +1336,7 @@ static void POINTS_unzip_raw(
  * This merge method works best when having both a lot of series and having
  * any number of points for each series.
  */
-static void POINTS_highest_and_merge(slist_t * plist, siridb_points_t * points)
+static void POINTS_highest_and_merge(vec_t * plist, siridb_points_t * points)
 {
     siridb_points_t ** m = NULL;
     size_t i, n, l = 0;
@@ -1415,7 +1407,7 @@ static void POINTS_highest_and_merge(slist_t * plist, siridb_points_t * points)
  * This merge method works best for only a few series with possible a lot
  * of points.
  */
-static void POINTS_sort_while_merge(slist_t * plist, siridb_points_t * points)
+static void POINTS_sort_while_merge(vec_t * plist, siridb_points_t * points)
 {
     siridb_points_t ** m;
     size_t i, n;
@@ -1460,7 +1452,7 @@ static void POINTS_sort_while_merge(slist_t * plist, siridb_points_t * points)
  * This merge method works best when having a lot of series with only one point
  * or when the total number of points it not so high.
  */
-static void POINTS_merge_and_sort(slist_t * plist, siridb_points_t * points)
+static void POINTS_merge_and_sort(vec_t * plist, siridb_points_t * points)
 {
     siridb_points_t ** m;
     size_t i, n;
index d1613782217e97466ac0f0586e1c05b4b181c11f..2c74486062379125ee01224bbf9ff0d427c683a8 100644 (file)
@@ -1,15 +1,6 @@
 /*
- * pool.c - Generate pool lookup.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 25-03-2016
- *
+ * pool.c - SiriDB pool containing one or two servers.
  */
-
 #include <assert.h>
 #include <logger/logger.h>
 #include <siri/db/pool.h>
index 81c6c0cc12efab66d0334195839645b4db734d35..44ddedd8565d952b7eda286255ea4825336c5b9f 100644 (file)
@@ -1,14 +1,6 @@
 /*
- * pools.c - Generate pools lookup.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-05-2016
+ * pools.c - Collection of pools.
  */
-
 #include <assert.h>
 #include <llist/llist.h>
 #include <logger/logger.h>
@@ -247,7 +239,7 @@ void siridb_pools_send_pkg(
                         "Cannot send package to pool '%u' "
                         "(no accessible server found)",
                         pid);
-                slist_append(promises->promises, NULL);
+                vec_append(promises->promises, NULL);
             }
         }
 
@@ -257,10 +249,10 @@ void siridb_pools_send_pkg(
 
 /*
  * This function will send a package to one accessible server in the pools
- * provided by the 'slist'. The promises call-back function should be
+ * provided by the 'vec'. The promises call-back function should be
  * used to check if the package has been send successfully to all pools.
  *
- * The 'slist' can be destroyed after this function has returned.
+ * The 'vec' can be destroyed after this function has returned.
  *
  * This function can raise a SIGNAL when allocation errors occur.
  *
@@ -270,7 +262,7 @@ void siridb_pools_send_pkg(
  * will always be destroyed.
  */
 void siridb_pools_send_pkg_2some(
-        slist_t * slist,
+        vec_t * vec,
         sirinet_pkg_t * pkg,
         uint64_t timeout,
         sirinet_promises_cb cb,
@@ -278,7 +270,7 @@ void siridb_pools_send_pkg_2some(
         int flags)
 {
     sirinet_promises_t * promises =
-            sirinet_promises_new(slist->len, cb, data, pkg);
+            sirinet_promises_new(vec->len, cb, data, pkg);
 
     if (promises == NULL)
     {
@@ -290,9 +282,9 @@ void siridb_pools_send_pkg_2some(
         siridb_pool_t * pool;
         size_t i;
 
-        for (i = 0; i < slist->len; i++)
+        for (i = 0; i < vec->len; i++)
         {
-            pool = slist->data[i];
+            pool = vec->data[i];
 
             if (siridb_pool_send_pkg(
                     pool,
@@ -305,7 +297,7 @@ void siridb_pools_send_pkg_2some(
                 log_debug(
                         "Cannot send package to at least on pool "
                         "(no accessible server found)");
-                slist_append(promises->promises, NULL);
+                vec_append(promises->promises, NULL);
             }
         }
 
index 8a178d701dab3f37d299898aa271ef9e43841729..4800798dbf03a52e2d08b43599e8f12d3f203225 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * presuf.c - Prefix and Suffix store.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-08-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
@@ -16,7 +8,7 @@
 #include <siri/grammar/grammar.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 
 siridb_presuf_t * PRESUF_add(siridb_presuf_t ** presuf);
@@ -80,7 +72,7 @@ siridb_presuf_t * siridb_presuf_add(
                 if (nps->prefix != NULL)
                 {
                     /* not critical if suffix is still NULL */
-                    nps->len += strx_extract_string(
+                    nps->len += xstr_extract_string(
                             nps->prefix,
                             ps_children->next->node->str,
                             ps_children->next->node->len);
@@ -92,7 +84,7 @@ siridb_presuf_t * siridb_presuf_add(
                 if (nps->suffix != NULL)
                 {
                     /* not critical if suffix is still NULL */
-                    nps->len += strx_extract_string(
+                    nps->len += xstr_extract_string(
                             nps->suffix,
                             ps_children->next->node->str,
                             ps_children->next->node->len);
index 9b01312f763fba274218f856b76979b98cab04ab..8ee3726b9de45a024818d38232ac945b998d8911 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * props.c - Functions to return SiriDB properties.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 17-03-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
index 1968416171c462a0f8e4ec49820a9ba96d6724b4..db0ae4b3dbd49613dcbfd25aa3bc09865d3ad11f 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * queries.c - Querie helpers for listener
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 03-05-2016
- *
+ * queries.c - Query helpers for listener.
  */
 #include <assert.h>
 #include <logger/logger.h>
@@ -24,8 +16,8 @@
 q->flags = 0;                       \
 q->series_map = NULL;               \
 q->series_tmp = NULL;               \
-q->slist = NULL;                    \
-q->slist_index = 0;                 \
+q->vec = NULL;                    \
+q->vec_index = 0;                 \
 q->pmap = NULL;                     \
 q->update_cb = NULL;                \
 q->where_expr = NULL;               \
@@ -46,15 +38,15 @@ if (q->series_tmp != NULL)                                      \
             q->series_tmp,                                      \
             (imap_free_cb) &siridb__series_decref);             \
 }                                                               \
-if (q->slist != NULL)                                           \
+if (q->vec != NULL)                                           \
 {                                                               \
     siridb_series_t * series;                                   \
-    for (; q->slist_index < q->slist->len; q->slist_index++)    \
+    for (; q->vec_index < q->vec->len; q->vec_index++)    \
     {                                                                   \
-        series = (siridb_series_t *) q->slist->data[q->slist_index];    \
+        series = (siridb_series_t *) q->vec->data[q->vec_index];    \
         siridb_series_decref(series);                                   \
     }                                                                   \
-    slist_free(q->slist);                                       \
+    vec_free(q->vec);                                       \
 }                                                               \
 if (q->where_expr != NULL)                                      \
 {                                                               \
@@ -69,7 +61,7 @@ pcre2_match_data_free(q->match_data);                           \
 free(q);                                                        \
 siridb_query_free(handle);
 
-static void QUERIES_free_merge_result(slist_t * plist);
+static void QUERIES_free_merge_result(vec_t * plist);
 
 query_select_t * query_select_new(void)
 {
@@ -225,11 +217,11 @@ void query_drop_free(uv_handle_t * handle)
         siridb_shard_t * shard;
         while (q_drop->shards_list->len)
         {
-            shard = (siridb_shard_t *) slist_pop(q_drop->shards_list);
+            shard = (siridb_shard_t *) vec_pop(q_drop->shards_list);
             siridb_shard_decref(shard);
         }
 
-        slist_free(q_drop->shards_list);
+        vec_free(q_drop->shards_list);
     }
 
     QUERIES_FREE(q_drop, handle)
@@ -242,7 +234,7 @@ void query_list_free(uv_handle_t * handle)
 
     if (q_list->props != NULL)
     {
-        slist_free(q_list->props);
+        vec_free(q_list->props);
     }
 
     QUERIES_FREE(q_list, handle)
@@ -296,7 +288,7 @@ void query_help_free(uv_handle_t * handle)
     siridb_query_free(handle);
 }
 
-static void QUERIES_free_merge_result(slist_t * plist)
+static void QUERIES_free_merge_result(vec_t * plist)
 {
     size_t i;
     for (i = 0; i < plist->len; i ++)
index 21fcdeb6b66b65e7f6e5eb0e344544c0e5941c7c..e0bb546c034934fab61ac66a7eeacd8698191a5e 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * query.c - Responsible for parsing queries.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
  */
 #include <assert.h>
 #include <cleri/cleri.h>
@@ -27,7 +19,7 @@
 #include <siri/net/pkg.h>
 #include <siri/net/clserver.h>
 #include <siri/siri.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 #include <sys/time.h>
 #include <siri/err.h>
@@ -276,7 +268,7 @@ void siridb_query_forward(
         case SIRIDB_QUERY_FWD_SERVERS:
             pkg->tp = BPROTO_QUERY_SERVER;
             {
-                slist_t * servers = siridb_servers_other2slist(siridb);
+                vec_t * servers = siridb_servers_other2vec(siridb);
                 if (servers != NULL)
                 {
                     siridb_servers_send_pkg(
@@ -285,7 +277,7 @@ void siridb_query_forward(
                             SIRIDB_FWD_SERVERS_TIMEOUT,
                             cb,
                             handle);
-                    slist_free(servers);
+                    vec_free(servers);
                 }
                 else
                 {
@@ -313,11 +305,11 @@ void siridb_query_forward(
                     handle->data)->data)->pmap != NULL);
             pkg->tp = BPROTO_QUERY_SERVER;
             {
-                slist_t * borrow_list = imap_slist(((query_select_t *) (
+                vec_t * borrow_list = imap_vec(((query_select_t *) (
                         (siridb_query_t *) handle->data)->data)->pmap);
                 if (borrow_list != NULL)
                 {
-                    /* if slist is NULL, a signal is raised */
+                    /* if vec is NULL, a signal is raised */
                     siridb_pools_send_pkg_2some(
                             borrow_list,
                             pkg,
@@ -828,7 +820,7 @@ static int QUERY_time_expr(
             char datestr[node->len - 1];
 
             /* extract date string */
-            strx_extract_string(datestr, node->str, node->len);
+            xstr_extract_string(datestr, node->str, node->len);
 
             /* get timestamp from date string */
             int64_t ts = iso8601_parse_date(datestr, walker->siridb->tz);
index 18fde412253f31fca96a272dc1b27449b8e48cb8..50b61ed6c9a90fdcdaffceefe0bcc097716d9800 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * re.c - Helpers for regular expressions
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-08-2016
- *
+ * re.c - Helpers for regular expressions.
  */
 #include <assert.h>
 #include <siri/db/db.h>
index 7087d59a7f7752faf4aa1c8fab2d3cf4bb2582a3..afebf0ff712c1494c3a652abc3c56c3878c80133 100644 (file)
@@ -1,13 +1,6 @@
 /*
  * reindex.c - SiriDB Re-index.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 27-07-2016
- *
  * Differences while re-indexing:
  *
  *  - Group information like number of series will be updated at a lower
index f2daa976ffc1b020c88c45d3fb1115bfbd87276f..5f222f1919d01a5a49a44a0973ff20a50b103c33 100644 (file)
@@ -1,14 +1,5 @@
 /*
  * replicate.c - Replicate SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 11-07-2016
- *
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
index 12e9598ba95beb4b6c8d691f587f567857c2038b..8d85ff730a74005b1e25f18eb42d3b6dbd955f8a 100644 (file)
@@ -1,12 +1,6 @@
 /*
- * series.c - Series
+ * series.c - SiriDB Time Series.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 29-03-2016
  *
  * Info siridb->series_mutex:
  *
@@ -351,7 +345,7 @@ void siridb__series_free(siridb_series_t *__restrict series)
         siridb_points_free(series->buffer);
         if (series->flags & SIRIDB_SERIES_IS_DROPPED)
         {
-            slist_append_safe(
+            vec_append_safe(
                 &series->siridb->buffer->empty,
                 (void *) series->bf_offset);
         }
index cfe7c0114de31cd97b1425db9d084080331eeae4..6648d3dabf01803c472c1894c890b7cde3865476 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * server.c - SiriDB Server.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 17-03-2016
- *
+ * server.c - Each SiriDB database has at least one server.
  */
 #include <assert.h>
 #include <logger/logger.h>
@@ -22,7 +14,7 @@
 #include <siri/net/tcp.h>
 #include <siri/siri.h>
 #include <siri/version.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 
 #define SIRIDB_SERVERS_FN "servers.dat"
@@ -832,7 +824,7 @@ siridb_server_t * siridb_server_from_node(
     case CLERI_TP_CHOICE:  /* server name   */
         {
             char name[server_node->len - 1];
-            strx_extract_string(name, server_node->str, server_node->len);
+            xstr_extract_string(name, server_node->str, server_node->len);
             server = siridb_servers_by_name(siridb->servers, name);
         }
         break;
index a083efbc1b9b4af65c49ede76fdc040602f13e90..8dcfdd57b57bd90a215054c9bea76879a9a446cb 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * servers.c - SiriDB Servers.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-06-2016
- *
+ * servers.c - Collection of SiriDB servers.
  */
 #include <assert.h>
 #include <llist/llist.h>
@@ -330,10 +322,10 @@ int siridb_servers_register(siridb_t * siridb, siridb_server_t * server)
  *
  * In case of an error, NULL is returned.
  */
-slist_t * siridb_servers_other2slist(siridb_t * siridb)
+vec_t * siridb_servers_other2vec(siridb_t * siridb)
 {
     siridb_server_t * server;
-    slist_t * servers = slist_new(siridb->servers->len - 1);
+    vec_t * servers = vec_new(siridb->servers->len - 1);
     llist_node_t * node;
 
     if (servers == NULL)
@@ -348,7 +340,7 @@ slist_t * siridb_servers_other2slist(siridb_t * siridb)
         server = node->data;
         if (server != siridb->server)
         {
-            slist_append(servers, server);
+            vec_append(servers, server);
         }
     }
 
@@ -364,7 +356,7 @@ slist_t * siridb_servers_other2slist(siridb_t * siridb)
  * using the arguments (NULL, data).
  */
 void siridb_servers_send_pkg(
-        slist_t * servers,
+        vec_t * servers,
         sirinet_pkg_t * pkg,
         uint64_t timeout,
         sirinet_promises_cb cb,
@@ -399,14 +391,14 @@ void siridb_servers_send_pkg(
                     log_critical(
                             "Allocation error while trying to send a package "
                             "to '%s'", server->name);
-                    slist_append(promises->promises, NULL);
+                    vec_append(promises->promises, NULL);
                 }
             }
             else
             {
                 log_debug("Cannot send package to '%s' (server is offline)",
                         server->name);
-                slist_append(promises->promises, NULL);
+                vec_append(promises->promises, NULL);
             }
 
         }
@@ -541,7 +533,7 @@ int siridb_servers_list(siridb_server_t * server, uv_async_t * handle)
 {
     siridb_query_t * query = handle->data;
     query_list_t * qlist = query->data;
-    slist_t * props = qlist->props;
+    vec_t * props = qlist->props;
     siridb_t * siridb = query->client->siridb;
     cexpr_t * where_expr = qlist->where_expr;
     size_t i;
index 8b5d4905fc7b415b270a8e6165646f20b2c2493a..007d4b4e826da63ee904bf4c56d1e68bfddfa635 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * shard.c - SiriDB Shard.
-
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-04-2016
- *
+ * shard.c - SiriDB shard file.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #include <siri/err.h>
 #include <siri/file/pointer.h>
 #include <siri/siri.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 
 
 /* max read buffer size used for reading from index file */
@@ -1054,7 +1045,7 @@ int siridb_shard_get_points_log32(
         {
             size_t slen;
             qp_via_t v;
-            v.str = strx_dup(cpt, &slen);
+            v.str = xstr_dup(cpt, &slen);
             cpt += slen + 1;
             uint64_t ts = *tpt;
             siridb_points_add_point(points, &ts, &v);
@@ -1066,7 +1057,7 @@ int siridb_shard_get_points_log32(
         {
             size_t slen;
             points->data[points->len].ts = *tpt;
-            points->data[points->len].val.str = strx_dup(cpt, &slen);
+            points->data[points->len].val.str = xstr_dup(cpt, &slen);
             cpt += slen + 1;
         }
     }
@@ -1171,7 +1162,7 @@ int siridb_shard_get_points_log64(
         {
             size_t slen;
             qp_via_t v;
-            v.str = strx_dup(cpt, &slen);
+            v.str = xstr_dup(cpt, &slen);
             cpt += slen + 1;
             siridb_points_add_point(points, tpt, &v);
         }
@@ -1182,7 +1173,7 @@ int siridb_shard_get_points_log64(
         {
             size_t slen;
             points->data[points->len].ts = *tpt;
-            points->data[points->len].val.str = strx_dup(cpt, &slen);
+            points->data[points->len].val.str = xstr_dup(cpt, &slen);
             cpt += slen + 1;
         }
     }
@@ -1265,11 +1256,11 @@ int siridb_shard_optimize(siridb_shard_t * shard, siridb_t * siridb)
 
     uv_mutex_lock(&siridb->series_mutex);
 
-    slist_t * slist = imap_2slist_ref(siridb->series_map);
+    vec_t * vec = imap_2vec_ref(siridb->series_map);
 
     uv_mutex_unlock(&siridb->series_mutex);
 
-    if (slist == NULL)
+    if (vec == NULL)
     {
         ERR_ALLOC
         return -1;
@@ -1277,7 +1268,7 @@ int siridb_shard_optimize(siridb_shard_t * shard, siridb_t * siridb)
 
     sleep(1);
 
-    for (i = 0; i < slist->len; i++)
+    for (i = 0; i < vec->len; i++)
     {
         /* its possible that another database is paused, but we wait anyway */
         if (siri.optimize->pause)
@@ -1285,7 +1276,7 @@ int siridb_shard_optimize(siridb_shard_t * shard, siridb_t * siridb)
             siri_optimize_wait();
         }
 
-        series = slist->data[i];
+        series = vec->data[i];
 
         if (    !siri_err &&
                 siri.optimize->status != SIRI_OPTIMIZE_CANCELLED &&
@@ -1316,7 +1307,7 @@ int siridb_shard_optimize(siridb_shard_t * shard, siridb_t * siridb)
         siridb_series_decref(series);
     }
 
-    slist_free(slist);
+    vec_free(vec);
 
     if (new_shard->flags & SIRIDB_SHARD_IS_REMOVED)
     {
@@ -1473,16 +1464,16 @@ void siridb_shard_drop(siridb_shard_t * shard, siridb_t * siridb)
      */
     if (optimizing)
     {
-        slist_t * slist = imap_2slist_ref(siridb->series_map);
+        vec_t * vec = imap_2vec_ref(siridb->series_map);
         size_t i;
 
-        if (slist == NULL)
+        if (vec == NULL)
         {
             ERR_ALLOC
         }
-        else for (i = 0; i < slist->len; i++)
+        else for (i = 0; i < vec->len; i++)
         {
-            series = (siridb_series_t *) slist->data[i];
+            series = (siridb_series_t *) vec->data[i];
             if (shard->id % siridb->duration_num == series->mask)
             {
                 siridb_series_remove_shard(siridb, series, shard);
@@ -1491,26 +1482,26 @@ void siridb_shard_drop(siridb_shard_t * shard, siridb_t * siridb)
             siridb_series_decref(series);
         }
 
-        slist_free(slist);
+        vec_free(vec);
     }
     else
     {
-        slist_t * slist = imap_2slist(siridb->series_map);
+        vec_t * vec = imap_2vec(siridb->series_map);
         size_t i;
 
-        if (slist == NULL)
+        if (vec == NULL)
         {
             ERR_ALLOC
         }
-        else for (i = 0; i < slist->len; i++)
+        else for (i = 0; i < vec->len; i++)
         {
-            series = (siridb_series_t *) slist->data[i];
+            series = (siridb_series_t *) vec->data[i];
             if (shard->id % siridb->duration_num == series->mask)
             {
                 siridb_series_remove_shard(siridb, series, shard);
             }
         }
-        slist_free(slist);
+        vec_free(vec);
     }
 
     if (pop_shard != NULL)
index 365800ab68720d74abd7ae2dff8c3f5755940eb4..290875ac7826e148b67d8488ded4b448ea8e5826 100644 (file)
@@ -1,12 +1,5 @@
 /*
- * shards.c - SiriDB shards.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-04-2016
+ * shards.c - Collection of SiriDB shards.
  *
  * Info shards->mutex:
  *
index 2d0bc494a280e896c4f444e8040b871b04a36da6..acfa6acefaa555c3504de824d39be3b55e2616c7 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * tasks.c - SiriDB Error.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 31-10-2016
- *
+ * tasks.c - Counters for info on SiriDB tasks.
  */
 #include <siri/db/tasks.h>
 #include <timeit/timeit.h>
index fd147e7c54b0032ddc42f5eafebaeb3e59aebd56..f2547cf8a41860db6fc4473dd7a823716a18c348 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * time.c - Time- and time precision functions and constants.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 09-03-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
index 25870c7d4428d44c4dc91c6293cda774a7250eae..8657b7cdd9c5fe0fe30d66792a0b3f16351be4c6 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * user.c - contains functions for a SiriDB database member.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-03-2016
- *
+ * user.c - Contains functions for a SiriDB database user.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
@@ -20,7 +12,7 @@
 #include <siri/db/users.h>
 #include <siri/err.h>
 #include <siri/grammar/grammar.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <owcrypt/owcrypt.h>
 #include <string.h>
 
@@ -109,7 +101,7 @@ int siridb_user_set_password(
         return -1;
     }
 
-    if (!strx_is_graph(password))
+    if (!xstr_is_graph(password))
     {
         if (err_msg != NULL)
         {
@@ -165,7 +157,7 @@ int siridb_user_set_name(
         return 1;
     }
 
-    if (!strx_is_graph(name))
+    if (!xstr_is_graph(name))
     {
         sprintf(err_msg,
                 "User name contains illegal characters. (only graphical "
index bd0615873576a05629df478af0c11869593d4721..f0a8f40dee031a9aca5bdc2fd8eff5adf1ad93a4 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * users.c - contains functions for a SiriDB database members.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 04-05-2016
- *
+ * users.c - Collection of database users.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
@@ -20,7 +12,7 @@
 #include <siri/db/misc.h>
 #include <siri/err.h>
 #include <stdlib.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 #include <time.h>
 #include <xpath/xpath.h>
index 78df62c188ab35d39d941505425d16f4647dbfd0..fed1ea0510474828ab4b4057d2e45646c76eb815 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * variance.c - Calculate variance for points.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 10-08-2016
- *
  */
 #include <assert.h>
 #include <math.h>
index ad3761483264ae08fda0c264e77deda7a19d7889..8754bb4f4fd45c375427336eaaa438ea5a53d48b 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * walker.h - creates enter and exit nodes
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 13-06-2016
- *
+ * walker.c - Creates enter and exit nodes.
  */
 #include <siri/db/walker.h>
 #include <siri/err.h>
index 20f169b6031786902e8ee7d5475aa99ea1edf5c8..a930394b3dd85e0553f172fec89cb454fb87c02f 100644 (file)
@@ -1,3 +1,6 @@
+/*
+ * err.c - SiriDB Error.
+ */
 #include <siri/err.h>
 
 int siri_err = 0;
index 844fa8d1134837a4d3ef8cc4d76b20f1db770277..b780f14e6fb0fc406aaed6fc9e02f93e638b9f01 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * filehandler.c - Filehandler for shard files.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-04-2016
- *
+ * handler.c - File handler for shard files.
  */
 #include <logger/logger.h>
 #include <siri/err.h>
index ed706f7d87d0cefdd28325edeca7cca114c59e71..4513d976dd91783a9ddb5388c58a551df1d1c46a 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * filepointer.h - File-pointer used in combination with file-handler.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-04-2016
- *
+ * pointer.c - File pointer used in combination with file handler.
  */
 #include <logger/logger.h>
 #include <siri/err.h>
index 9e8f23f6ac104641328cac3118386401d0bda0d0..7c659f8bbcce548333cce34325ad4b1ca24d1008 100644 (file)
@@ -1,17 +1,9 @@
 /*
  * heartbeat.c - Heart-beat task SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
  * There is one and only one heart-beat task thread running for SiriDB. For
  * this reason we do not need to parse data but we should only take care for
  * locks while writing data.
- *
- * changes
- *  - initial version, 17-06-2016
- *
  */
 #include <logger/logger.h>
 #include <siri/db/server.h>
index 4c6a1ad71628e069778cc425a56e69207c02ff16..bf6205872983fe6a28ca3e426f354ad385b8ddf9 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * help.c - Help for SiriDB
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 23-09-2016
- *
+ * help.c - Help for SiriDB.
  */
 #include <limits.h>
 #include <logger/logger.h>
index 85a527dd01a19e8911d90b6258c7703b8009ba69..f2a36b862f9ac2cc9a8821a512863a8c9462c43b 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * bserver.c - Back-end Server SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 18-06-2016
- *
+ * bserver.c - Listen to back-end SiriDB Server.
  */
 #include <assert.h>
 #include <logger/logger.h>
index bd0bcbc94debc8b0c17cd47ebe12c634abcf3206..01da4499b308f98b3df5352d9f7307206861ef65 100644 (file)
@@ -1,14 +1,5 @@
-
 /*
- * clserver.c - TCP server for serving client requests.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 09-03-2016
- *
+ * clserver.c - Listen for client requests.
  */
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
@@ -19,8 +10,8 @@
 #include <logger/logger.h>
 #include <qpack/qpack.h>
 #include <siri/siri.h>
-#include <siri/admin/account.h>
-#include <siri/admin/request.h>
+#include <siri/service/account.h>
+#include <siri/service/request.h>
 #include <siri/db/access.h>
 #include <siri/db/auth.h>
 #include <siri/db/insert.h>
@@ -86,7 +77,7 @@ static void on_reqfile(
         sirinet_pkg_t * pkg,
         sirinet_clserver_getfile getfile);
 static void on_register_server(sirinet_stream_t * client, sirinet_pkg_t * pkg);
-static void on_req_admin(sirinet_stream_t * client, sirinet_pkg_t * pkg);
+static void on_req_service(sirinet_stream_t * client, sirinet_pkg_t * pkg);
 static void CLSERVER_send_server_error(
         siridb_t * siridb,
         sirinet_stream_t * client,
@@ -95,7 +86,7 @@ static void CLSERVER_send_pool_error(
         sirinet_stream_t * client,
         sirinet_pkg_t * pkg);
 static void CLSERVER_on_register_server_response(
-        slist_t * promises,
+        vec_t * promises,
         siridb_server_async_t * server_reg);
 
 #define POOL_ERR_MSG \
@@ -307,8 +298,8 @@ static void on_data(sirinet_stream_t * client, sirinet_pkg_t * pkg)
         case CPROTO_REQ_FILE_DATABASE:
             on_reqfile(client, pkg, siridb_get_file);
             break;
-        case CPROTO_REQ_ADMIN:
-            on_req_admin(client, pkg);
+        case CPROTO_REQ_SERVICE:
+            on_req_service(client, pkg);
             break;
         }
     }
@@ -710,7 +701,7 @@ static void on_register_server(sirinet_stream_t * client, sirinet_pkg_t * pkg)
     sirinet_pkg_t * package = NULL;
     siridb_server_t * new_server = NULL;
     char err_msg[SIRIDB_MAX_SIZE_ERR_MSG];
-    slist_t * servers = NULL;
+    vec_t * servers = NULL;
 
     if (siridb->server->flags != SERVER_FLAG_RUNNING)
     {
@@ -760,7 +751,7 @@ static void on_register_server(sirinet_stream_t * client, sirinet_pkg_t * pkg)
     else
     {
         /* make a copy of the current servers */
-        servers = siridb_servers_other2slist(siridb);
+        servers = siridb_servers_other2vec(siridb);
         if (servers == NULL)
         {
             sprintf(err_msg, "Memory allocation error.");
@@ -826,10 +817,10 @@ static void on_register_server(sirinet_stream_t * client, sirinet_pkg_t * pkg)
     }
 
     /* free the servers or NULL */
-    slist_free(servers);
+    vec_free(servers);
 }
 
-static void on_req_admin(sirinet_stream_t * client, sirinet_pkg_t * pkg)
+static void on_req_service(sirinet_stream_t * client, sirinet_pkg_t * pkg)
 {
     qp_unpacker_t unpacker;
     qp_packer_t * packer = NULL;
@@ -846,14 +837,14 @@ static void on_req_admin(sirinet_stream_t * client, sirinet_pkg_t * pkg)
             qp_next(&unpacker, &qp_password) == QP_RAW &&
             qp_next(&unpacker, &qp_request) == QP_INT64)
     {
-        tp = (siri_admin_account_check(
+        tp = (siri_service_account_check(
                 &siri,
                 &qp_username,
                 &qp_password,
                 err_msg)) ?
-            CPROTO_ERR_ADMIN
+            CPROTO_ERR_SERVICE
             :
-            siri_admin_request(
+            siri_service_request(
                     qp_request.via.int64,
                     &unpacker,
                     &qp_username,
@@ -864,33 +855,33 @@ static void on_req_admin(sirinet_stream_t * client, sirinet_pkg_t * pkg)
 
         package =
                 (tp == CPROTO_DEFERRED) ? NULL :
-                (tp == CPROTO_ERR_ADMIN) ? sirinet_pkg_err(
+                (tp == CPROTO_ERR_SERVICE) ? sirinet_pkg_err(
                         pkg->pid,
                         strlen(err_msg),
                         tp,
                         err_msg) :
-                (tp == CPROTO_ACK_ADMIN_DATA) ? sirinet_packer2pkg(
+                (tp == CPROTO_ACK_SERVICE_DATA) ? sirinet_packer2pkg(
                         packer,
                         pkg->pid,
                         tp) : sirinet_pkg_new(pkg->pid, 0, tp, NULL);
     }
     else
     {
-        log_error("Invalid administrative request received.");
+        log_error("Invalid service request received.");
         package = sirinet_pkg_new(
                 pkg->pid,
                 0,
-                CPROTO_ERR_ADMIN_INVALID_REQUEST,
+                CPROTO_ERR_SERVICE_INVALID_REQUEST,
                 NULL);
     }
     if (package != NULL)
     {
         switch (package->tp)
         {
-        case CPROTO_ERR_ADMIN_INVALID_REQUEST:
+        case CPROTO_ERR_SERVICE_INVALID_REQUEST:
             log_warning("Received an invalid manage request.");
             break;
-        case CPROTO_ERR_ADMIN:
+        case CPROTO_ERR_SERVICE:
             log_warning("Error handling manage request: %s", err_msg);
             break;
         }
@@ -904,7 +895,7 @@ static void on_req_admin(sirinet_stream_t * client, sirinet_pkg_t * pkg)
  * Typedef: sirinet_promises_cb
  */
 static void CLSERVER_on_register_server_response(
-        slist_t * promises,
+        vec_t * promises,
         siridb_server_async_t * server_reg)
 {
     if (promises != NULL)
index acf8b0f0dee4c5f51400c98678effebf96752082..8ca2d40562e23b681329990cc03e81cd2d9d99e2 100644 (file)
@@ -1,3 +1,6 @@
+/*
+ * pipe.c - Named Pipe support.
+ */
 #include <assert.h>
 #include <string.h>
 #include <stdlib.h>
index 5a78260b73b536eb546e7394075197d1eccfe8b2..883c3c9d3d3334d65a96ae640e57da1ed06e95cf 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * pkg.c - SiriDB Package type.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 18-06-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
index 528756bdfe9852ddd93cc1556caed1a9048a9b51..7113de47b9a696936372562c2025b2b1665258b4 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * promise.c - Promise SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 23-06-2016
- *
+ * promise.c - Promise used for sending to data to SiriDB servers.
  */
 #include <assert.h>
 #include <logger/logger.h>
index 1139b53af1f52fcecc5f735ebcbda486f32b1d86..80bdea0b4a865fd8c46640cf58758a5b33d60b2e 100644 (file)
@@ -1,14 +1,5 @@
 /*
- * promises.c - Promises SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- *
- * changes
- *  - initial version, 13-07-2016
- *
+ * promises.c - Collection for promised.
  */
 #include <assert.h>
 #include <logger/logger.h>
@@ -36,7 +27,7 @@ sirinet_promises_t * sirinet_promises_new(
 
         promises->cb = cb;
         promises->data = data;
-        promises->promises = slist_new(size);
+        promises->promises = vec_new(size);
         promises->pkg = pkg;
 
         if (promises->promises == NULL)
@@ -53,7 +44,7 @@ sirinet_promises_t * sirinet_promises_new(
  * This function can be used to free promises with data. It assumes
  * data simple can be destroyed with simple calling free().
  */
-void sirinet_promises_llist_free(slist_t * promises)
+void sirinet_promises_llist_free(vec_t * promises)
 {
     sirinet_promise_t * promise;
     size_t i;
@@ -99,7 +90,7 @@ void sirinet_promises_on_response(
         promise->data = (void *) sirinet_pkg_dup(pkg);
     }
 
-    slist_append(promises->promises, (void *) promise);
+    vec_append(promises->promises, (void *) promise);
 
     SIRINET_PROMISES_CHECK(promises)
 }
index a4a2b0087de60f115f29469fd4f1a547112fc61d..856948ced95dff07e2a8c494d78467a7b16f82e8 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * protocol.c - Protocol for SiriDB.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 01-08-2016
- *
+ * protocol.c - Protocol definitions for SiriDB.
  */
 #include <siri/net/protocol.h>
 #include <stdio.h>
@@ -31,7 +23,7 @@ const char * sirinet_cproto_client_str(cproto_client_t n)
     case CPROTO_REQ_FILE_DATABASE: return "CPROTO_REQ_FILE_DATABASE";
     /* end internal usage */
 
-    case CPROTO_REQ_ADMIN: return "CPROTO_REQ_ADMIN";
+    case CPROTO_REQ_SERVICE: return "CPROTO_REQ_SERVICE";
 
     default:
         sprintf(protocol_str, "CPROTO_CLIENT_TYPE_UNKNOWN (%d)", n);
@@ -49,8 +41,8 @@ const char * sirinet_cproto_server_str(cproto_server_t n)
     case CPROTO_RES_ACK: return "CPROTO_RES_ACK";
     case CPROTO_RES_FILE: return "CPROTO_RES_FILE";
 
-    case CPROTO_ACK_ADMIN: return "CPROTO_ACK_ADMIN";
-    case CPROTO_ACK_ADMIN_DATA: return "CPROTO_ACK_ADMIN_DATA";
+    case CPROTO_ACK_SERVICE: return "CPROTO_ACK_SERVICE";
+    case CPROTO_ACK_SERVICE_DATA: return "CPROTO_ACK_SERVICE_DATA";
 
     case CPROTO_ERR_MSG: return "CPROTO_ERR_MSG";
     case CPROTO_ERR_QUERY: return "CPROTO_ERR_QUERY";
@@ -63,8 +55,8 @@ const char * sirinet_cproto_server_str(cproto_server_t n)
     case CPROTO_ERR_AUTH_CREDENTIALS: return "CPROTO_ERR_AUTH_CREDENTIALS";
     case CPROTO_ERR_AUTH_UNKNOWN_DB: return "CPROTO_ERR_AUTH_UNKNOWN_DB";
     case CPROTO_ERR_FILE: return "CPROTO_ERR_FILE";
-    case CPROTO_ERR_ADMIN: return "CPROTO_ERR_ADMIN";
-    case CPROTO_ERR_ADMIN_INVALID_REQUEST: return "CPROTO_ERR_ADMIN_INVALID_REQUEST";
+    case CPROTO_ERR_SERVICE: return "CPROTO_ERR_SERVICE";
+    case CPROTO_ERR_SERVICE_INVALID_REQUEST: return "CPROTO_ERR_SERVICE_INVALID_REQUEST";
     default:
         sprintf(protocol_str, "CPROTO_SERVER_TYPE_UNKNOWN (%d)", n);
         return protocol_str;
index 32c94695102b0ec8afeee69df992855a0cdbd12b..10e151cc04d61fb186e1843f79cdff1460d97056 100644 (file)
@@ -1,17 +1,9 @@
 /*
- * stream.c - Handle Stream request.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 09-03-2016
- *
+ * stream.c - For handling streams.
  */
 #include <assert.h>
 #include <logger/logger.h>
-#include <siri/admin/client.h>
+#include <siri/service/client.h>
 #include <siri/err.h>
 #include <siri/net/protocol.h>
 #include <siri/net/stream.h>
@@ -276,7 +268,7 @@ void sirinet__stream_free(uv_stream_t * uvclient)
         }
         break;
     case STREAM_TCP_MANAGE:  /* a server manage connection  */
-        siri_admin_client_free((siri_admin_client_t *) client->origin);
+        siri_service_client_free((siri_service_client_t *) client->origin);
         siri.client = NULL;
         break;
     }
index 99fc9ee2f4ce265463f4db766827e0a7f14e239a..e3d5ea005a5e61a8b4bcf9fe8ab84a20495866e2 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * tcp.c - Handle TCP request.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 09-03-2016
- *
+ * tcp.c - TCP support.
  */
 #include <siri/net/tcp.h>
 #include <stdlib.h>
index c55adf191b8c4a854fe639e34e49211789fb7248..624540165b8af39e701a1eded09d3a71dff8a321 100644 (file)
@@ -1,28 +1,20 @@
 /*
  * optimize.c - Optimize task SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
  * There is one and only one optimize task thread running for SiriDB. For this
  * reason we do not need to parse data but we should only take care for locks
  * while writing data.
  *
- *
  * Thread debugging:
  *  log_debug("getpid: %d - pthread_self: %lu",getpid(), pthread_self());
  *
- * changes
- *  - initial version, 09-05-2016
- *
  */
 #include <assert.h>
 #include <logger/logger.h>
 #include <siri/db/shard.h>
 #include <siri/optimize.h>
 #include <siri/siri.h>
-#include <slist/slist.h>
+#include <vec/vec.h>
 #include <unistd.h>
 
 static siri_optimize_t optimize = {
@@ -33,7 +25,7 @@ static siri_optimize_t optimize = {
 };
 
 static void OPTIMIZE_work(uv_work_t * work);
-static void OPTIMIZE_cleanup(slist_t * slsiridb);
+static void OPTIMIZE_cleanup(vec_t * slsiridb);
 static void OPTIMIZE_work_finish(uv_work_t * work, int status);
 static void OPTIMIZE_cb(uv_timer_t * handle);
 
@@ -264,8 +256,8 @@ static void OPTIMIZE_work(uv_work_t * work  __attribute__((unused)))
      * Optimize Thread
      */
 
-    slist_t * slsiridb;
-    slist_t * slshards;
+    vec_t * slsiridb;
+    vec_t * slshards;
     siridb_t * siridb;
     siridb_shard_t * shard;
     uint8_t c = siri.cfg->shard_compression;
@@ -280,7 +272,7 @@ static void OPTIMIZE_work(uv_work_t * work  __attribute__((unused)))
 
     uv_mutex_lock(&siri.siridb_mutex);
 
-    slsiridb = llist2slist(siri.siridb_list);
+    slsiridb = llist2vec(siri.siridb_list);
     if (slsiridb != NULL)
     {
         for (i = 0; i < slsiridb->len; i++)
@@ -307,7 +299,7 @@ static void OPTIMIZE_work(uv_work_t * work  __attribute__((unused)))
 
         uv_mutex_lock(&siridb->shards_mutex);
 
-        slshards = imap_2slist_ref(siridb->shards);
+        slshards = imap_2vec_ref(siridb->shards);
 
         uv_mutex_unlock(&siridb->shards_mutex);
 
@@ -370,7 +362,7 @@ static void OPTIMIZE_work(uv_work_t * work  __attribute__((unused)))
             siridb_shard_decref(shard);
         }
 
-        slist_free(slshards);
+        vec_free(slshards);
 
         if (siri_optimize_wait() == SIRI_OPTIMIZE_CANCELLED)
         {
@@ -381,7 +373,7 @@ static void OPTIMIZE_work(uv_work_t * work  __attribute__((unused)))
     OPTIMIZE_cleanup(slsiridb);
 }
 
-static void OPTIMIZE_cleanup(slist_t * slsiridb)
+static void OPTIMIZE_cleanup(vec_t * slsiridb)
 {
     if (slsiridb != NULL)
     {
@@ -394,7 +386,7 @@ static void OPTIMIZE_cleanup(slist_t * slsiridb)
             siridb_decref(siridb);
         }
 
-        slist_free(slsiridb);
+        vec_free(slsiridb);
     }
 }
 
diff --git a/src/siri/service/account.c b/src/siri/service/account.c
new file mode 100644 (file)
index 0000000..67e6a9c
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * account.c - SiriDB Service Account.
+ */
+#include <siri/service/account.h>
+#include <stddef.h>
+#include <owcrypt/owcrypt.h>
+#include <xpath/xpath.h>
+#include <siri/siri.h>
+#include <stdarg.h>
+#include <logger/logger.h>
+
+#define SIRI_SERVICE_ACCOUNT_SCHEMA 1
+#define FILENAME ".accounts.dat"
+
+#define DEFAULT_ACCOUNT "sa"
+#define DEFAULT_PASSWORD "siri"
+
+static int ACCOUNT_free(siri_service_account_t * account, void * args);
+static int ACCOUNT_save(siri_service_account_t * account, qp_fpacker_t * fpacker);
+static void ACCOUNT_msg(char * err_msg, char * fmt, ...);
+static int ACCOUNT_cmp(
+        siri_service_account_t * account,
+        qp_obj_t * qp_account);
+
+/*
+ * Initialize siri->accounts. Returns 0 if successful or -1 in case of an error
+ * (a signal might be raised because of qpack)
+ */
+int siri_service_account_init(siri_t * siri)
+{
+    qp_unpacker_t * unpacker;
+    qp_obj_t qp_schema;
+    qp_obj_t qp_account;
+    qp_obj_t qp_password;
+    int rc = 0;
+
+    /* get service accounts file name */
+    char fn[strlen(siri->cfg->default_db_path) + strlen(FILENAME) + 1];
+
+    /* initialize linked list */
+    siri->accounts = llist_new();
+    if (siri->accounts == NULL)
+    {
+        return -1;
+    }
+
+    /* make filename */
+    sprintf(fn, "%s%s", siri->cfg->default_db_path, FILENAME);
+
+    if (!xpath_file_exist(fn))
+    {
+        /* missing file, lets create the first account */
+        qp_account.via.raw = (unsigned char *) DEFAULT_ACCOUNT;
+        qp_account.len = 4;
+        qp_password.via.raw = (unsigned char *) DEFAULT_PASSWORD;
+        qp_password.len = 4;
+
+        return (siri_service_account_new(
+                siri,
+                &qp_account,
+                &qp_password,
+                0,
+                NULL) || siri_service_account_save(siri, NULL));
+    }
+
+    if ((unpacker = qp_unpacker_ff(fn)) == NULL)
+    {
+        return -1;  /* a signal is raised is case of a memory error */
+    }
+
+    if (    !qp_is_array(qp_next(unpacker, NULL)) ||
+            qp_next(unpacker, &qp_schema) != QP_INT64 ||
+            qp_schema.via.int64 != SIRI_SERVICE_ACCOUNT_SCHEMA)
+    {
+        log_critical("Invalid schema detected in '%s'", fn);
+        qp_unpacker_ff_free(unpacker);
+        return -1;
+    }
+
+    while ( rc == 0 &&
+            qp_is_array(qp_next(unpacker, NULL)) &&
+            qp_next(unpacker, &qp_account) == QP_RAW &&
+            qp_next(unpacker, &qp_password) == QP_RAW &&
+            qp_password.len > 12)  /* old and new passwords are > 12 */
+    {
+        rc = siri_service_account_new(siri, &qp_account, &qp_password, 1, NULL);
+    }
+
+    qp_unpacker_ff_free(unpacker);
+    return rc;
+}
+
+/*
+ * Creates a new service account and returns 0 if successful. In case of
+ * an error, -1 is returned, err_msg is set.
+ *
+ * When successful, the account is added to the siri->accounts linked list.
+ *
+ * is_encrypted should be zero if the password is not encrypted yet.
+ *
+ * Note: the account will not be saved to disk. Call siri_service_account_save()
+ *       to save a new service account.
+ */
+int siri_service_account_new(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        qp_obj_t * qp_password,
+        int is_encrypted,
+        char * err_msg)
+{
+    siri_service_account_t * account;
+
+    account = (siri_service_account_t *) llist_get(
+            siri->accounts,
+            (llist_cb) ACCOUNT_cmp,
+            (void *) qp_account);
+
+    if (account != NULL)
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "service account '%.*s' already exists",
+                (int) qp_account->len,
+                qp_account->via.raw);
+        return -1;
+    }
+
+    if (qp_account->len < 2)
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "service account name should have at least 2 characters");
+        return -1;
+    }
+
+    if (qp_password->len < 2)
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "service account password should have at least 2 characters");
+        return -1;
+    }
+
+    account = (siri_service_account_t *) malloc(sizeof(siri_service_account_t));
+    if (account == NULL)
+    {
+        ACCOUNT_msg(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    account->account = strndup(
+            (const char *) qp_account->via.raw, qp_account->len);
+    account->password = strndup(
+            (const char *) qp_password->via.raw, qp_password->len);
+
+    if (!is_encrypted && account->password != NULL)
+    {
+        char encrypted[OWCRYPT_SZ];
+        char salt[OWCRYPT_SALT_SZ];
+
+        /* generate a random salt */
+        owcrypt_gen_salt(salt);
+
+        /* encrypt the accounts password */
+        owcrypt(account->password, salt, encrypted);
+
+        /* replace with encrypted password */
+        free(account->password);
+        account->password = strdup(encrypted);
+    }
+
+    if (    account->account == NULL ||
+            account->password == NULL ||
+            llist_append(siri->accounts, account))
+    {
+        ACCOUNT_msg(err_msg, "memory allocation error");
+        return -1;
+    }
+    return 0;
+}
+
+/*
+ * Returns 0 if the account/password is valid or another value if not.
+ */
+int siri_service_account_check(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        qp_obj_t * qp_password,
+        char * err_msg)
+{
+    siri_service_account_t * account;
+    char pw[OWCRYPT_SZ];
+    char * password;
+
+    account = (siri_service_account_t *) llist_get(
+            siri->accounts,
+            (llist_cb) ACCOUNT_cmp,
+            (void *) qp_account);
+
+    if (account == NULL)
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "cannot find service account '%.*s'",
+                (int) qp_account->len,
+                qp_account->via.raw);
+        return -1;
+    }
+
+    password= strndup(
+            (const char *) qp_password->via.raw, qp_password->len);
+
+    if (password == NULL)
+    {
+        ACCOUNT_msg(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    owcrypt(password, account->password, pw);
+    free(password);
+
+    if (strcmp(pw, account->password))
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "incorrect password for service account '%.*s'",
+                (int) qp_account->len,
+                qp_account->via.raw);
+        return -1;
+    }
+
+    return 0;
+}
+
+/*
+ * Returns 0 if the password is successful changed or -1 if not.
+ *
+ * Note: the password change is not saved, call siri_service_account_save().
+ */
+int siri_service_account_change_password(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        qp_obj_t * qp_password,
+        char * err_msg)
+{
+    siri_service_account_t * account;
+    char encrypted[OWCRYPT_SZ];
+    char salt[OWCRYPT_SALT_SZ];
+    char * password;
+
+    account = (siri_service_account_t *) llist_get(
+            siri->accounts,
+            (llist_cb) ACCOUNT_cmp,
+            (void *) qp_account);
+
+    if (account == NULL)
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "cannot find service account '%.*s'",
+                (int) qp_account->len,
+                qp_account->via.raw);
+        return -1;
+    }
+
+    password= strndup(
+            (const char *) qp_password->via.raw, qp_password->len);
+
+    if (password == NULL)
+    {
+        ACCOUNT_msg(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    /* generate a random salt */
+    owcrypt_gen_salt(salt);
+
+    /* encrypt the accounts password */
+    owcrypt(password, salt, encrypted);
+
+    free(password);
+
+    password = strdup(encrypted);
+    if (password == NULL)
+    {
+        ACCOUNT_msg(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    /* replace account password with new encrypted password */
+    free(account->password);
+    account->password = password;
+
+    return 0;
+}
+
+/*
+ * Returns 0 if dropped or -1 in case the account was not found.
+ *
+ * Note: accounts are not saved, call siri_service_account_save().
+ */
+int siri_service_account_drop(
+        siri_t * siri,
+        qp_obj_t * qp_account,
+        char * err_msg)
+{
+    siri_service_account_t * account;
+    account = (siri_service_account_t *) llist_remove(
+            siri->accounts,
+            (llist_cb) ACCOUNT_cmp,
+            (void *) qp_account);
+    if (account == NULL)
+    {
+        ACCOUNT_msg(
+                err_msg,
+                "cannot find service account '%.*s'",
+                (int) qp_account->len,
+                qp_account->via.raw);
+        return -1;
+    }
+
+    ACCOUNT_free(account, NULL);
+    return 0;
+}
+
+/*
+ * Destroy service accounts. siri->accounts is allowed to be NULL.
+ */
+void siri_service_account_destroy(siri_t * siri)
+{
+    if (siri->accounts != NULL)
+    {
+        llist_free_cb(siri->accounts, (llist_cb) ACCOUNT_free, NULL);
+    }
+}
+
+/*
+ * Returns 0 if successful or EOF if not.
+ */
+int siri_service_account_save(siri_t * siri, char * err_msg)
+{
+    qp_fpacker_t * fpacker;
+
+    /* get service accounts file name */
+    char fn[strlen(siri->cfg->default_db_path) + strlen(FILENAME) + 1];
+
+    /* make filename */
+    sprintf(fn, "%s%s", siri->cfg->default_db_path, FILENAME);
+
+    if (
+        /* open a new account file */
+        (fpacker = qp_open(fn, "w")) == NULL ||
+
+        /* open a new array */
+        qp_fadd_type(fpacker, QP_ARRAY_OPEN) ||
+
+        /* write the current schema */
+        qp_fadd_int16(fpacker, SIRI_SERVICE_ACCOUNT_SCHEMA) ||
+
+        /* we can and should skip this if we have no accounts to save */
+        llist_walk(siri->accounts, (llist_cb) ACCOUNT_save, fpacker) ||
+
+        /* close file pointer */
+        qp_close(fpacker))
+    {
+        ACCOUNT_msg(err_msg, "error saving service accounts");
+        return EOF;
+    }
+    return 0;
+}
+
+/*
+ * Destroy an account.
+ */
+static int ACCOUNT_free(
+        siri_service_account_t * account,
+        void * args __attribute__((unused)))
+{
+    free(account->account);
+    free(account->password);
+    free(account);
+    return 0;
+}
+
+/*
+ * Returns 0 if successful and -1 in case an error occurred.
+ */
+static int ACCOUNT_save(siri_service_account_t * account, qp_fpacker_t * fpacker)
+{
+    int rc = 0;
+
+    rc += qp_fadd_type(fpacker, QP_ARRAY2);
+    rc += qp_fadd_string(fpacker, account->account);
+    rc += qp_fadd_string(fpacker, account->password);
+
+    return rc;
+}
+
+static void ACCOUNT_msg(char * err_msg, char * fmt, ...)
+{
+    va_list args;
+    va_start(args, fmt);
+    if (err_msg != NULL)
+    {
+        vsnprintf(err_msg, SIRI_MAX_SIZE_ERR_MSG, fmt, args);
+    }
+    else
+    {
+        log_error(fmt, args);
+    }
+    va_end(args);
+}
+
+static int ACCOUNT_cmp(
+        siri_service_account_t * account,
+        qp_obj_t * qp_account)
+{
+    size_t len = strlen(account->account);
+    return (len == qp_account->len && strncmp(
+            account->account,
+            (const char *) qp_account->via.raw,
+            len) == 0);
+}
diff --git a/src/siri/service/client.c b/src/siri/service/client.c
new file mode 100644 (file)
index 0000000..ffbace2
--- /dev/null
@@ -0,0 +1,1236 @@
+/*
+ * client.c - Client for expanding a SiriDB database.
+ */
+#include <string.h>
+#include <stdarg.h>
+#include <lock/lock.h>
+#include <logger/logger.h>
+#include <siri/siri.h>
+#include <siri/version.h>
+#include <siri/service/client.h>
+#include <siri/service/request.h>
+#include <siri/net/stream.h>
+#include <siri/net/protocol.h>
+#include <siri/net/tcp.h>
+#include <siri/db/server.h>
+
+/* 15 seconds  */
+#define CLIENT_REQUEST_TIMEOUT 15000
+#define CLIENT_FLAGS_TIMEOUT 1
+#define CLIENT_FLAGS_NO_ROLLBACK 2
+#define MAX_VERSION_LEN 256
+
+enum
+{
+    CLIENT_REQUEST_INIT,
+    CLIENT_REQUEST_STATUS,
+    CLIENT_REQUEST_POOLS,
+    CLIENT_REQUEST_FILE_USERS,
+    CLIENT_REQUEST_FILE_GROUPS,
+    CLIENT_REQUEST_FILE_SERVERS,
+    CLIENT_REQUEST_FILE_DATABASE,
+    CLIENT_REQUEST_REGISTER_SERVER
+};
+
+static void CLIENT_write_cb(uv_write_t * req, int status);
+static void CLIENT_on_connect(uv_connect_t * req, int status);
+static void CLIENT_on_data(sirinet_stream_t * client, sirinet_pkg_t * pkg);
+static void CLIENT_request_timeout(uv_timer_t * handle);
+static void CLIENT_on_auth_success(siri_service_client_t * adm_client);
+static int CLIENT_resolve_dns(
+        siri_service_client_t * adm_client,
+        int ai_family,
+        char * err_msg);
+static void CLIENT_on_resolved(
+        uv_getaddrinfo_t * resolver,
+        int status,
+        struct addrinfo * res);
+static void CLIENT_err(
+        siri_service_client_t * adm_client,
+        const char * fmt,
+        ...);
+static void CLIENT_send_pkg(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_error_msg(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_register_server(siri_service_client_t * adm_client);
+static void CLIENT_on_file_database(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_file_servers(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_file_groups(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_file_users(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_request_pools(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+static void CLIENT_on_request_status(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg);
+
+/*
+ * Initializes a request for a new pool or replica and returns 0 when
+ * successful. In case of an error, err_msg will be set and a value other than
+ * 0 is returned. (a signal can be raised.) When successful and only when
+ * successful, a response will be send to the provided client using the given
+ * pid.
+ */
+int siri_service_client_request(
+        uint16_t pid,
+        uint16_t port,
+        int pool,
+        uuid_t * uuid,
+        qp_obj_t * host,
+        qp_obj_t * username,
+        qp_obj_t * password,
+        qp_obj_t * dbname,
+        const char * dbpath,
+        sirinet_stream_t * client,
+        char * err_msg)
+{
+    siri_service_client_t * adm_client;
+    struct in_addr sa;
+    struct in6_addr sa6;
+
+    if (siri.client != NULL)
+    {
+        sprintf(err_msg, "manage socket already in use");
+        return -1;
+    }
+
+    siri.client = sirinet_stream_new(STREAM_TCP_MANAGE, &CLIENT_on_data);
+    if (siri.client == NULL)
+    {
+        sprintf(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    uv_tcp_init(siri.loop, (uv_tcp_t *) siri.client->stream);
+
+    adm_client = (siri_service_client_t *) malloc(sizeof(siri_service_client_t));
+    if (adm_client == NULL)
+    {
+        sirinet_stream_decref(siri.client);
+        sprintf(err_msg, "memory allocation error");
+        return -1;
+    }
+    adm_client->pid = pid;
+    adm_client->port = port;
+    adm_client->host = strndup(
+            (const char *) host->via.raw, host->len);
+    adm_client->username = strndup(
+            (const char *) username->via.raw, username->len);
+    adm_client->password = strndup(
+            (const char *) password->via.raw, password->len);
+    adm_client->dbname = strndup(
+            (const char *) dbname->via.raw, dbname->len);
+    adm_client->dbpath = strdup(dbpath);
+    adm_client->client = client;
+    adm_client->request = CLIENT_REQUEST_INIT;
+    adm_client->flags = 0;
+    adm_client->pool = pool;
+    memcpy(&adm_client->uuid, uuid, 16);
+
+
+    siri.client->origin = (void *) adm_client;
+
+    sirinet_stream_incref(adm_client->client);
+
+    if (adm_client->host == NULL ||
+        adm_client->username == NULL ||
+        adm_client->password == NULL ||
+        adm_client->dbname == NULL ||
+        adm_client->dbpath == NULL)
+    {
+        sirinet_stream_decref(siri.client);
+        sprintf(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    if (inet_pton(AF_INET, adm_client->host, &sa))
+    {
+        /* IPv4 */
+        struct sockaddr_in dest;
+
+        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
+        if (req == NULL)
+        {
+            sirinet_stream_decref(siri.client);
+            sprintf(err_msg, "memory allocation error");
+            return -1;
+        }
+        log_debug(
+                "Trying to connect to '%s:%u'...",
+                adm_client->host,
+                adm_client->port);
+
+        uv_ip4_addr(adm_client->host, adm_client->port, &dest);
+        uv_tcp_connect(
+                req,
+                (uv_tcp_t *) siri.client->stream,
+                (const struct sockaddr *) &dest,
+                CLIENT_on_connect);
+    }
+    else if (inet_pton(AF_INET6, adm_client->host, &sa6))
+    {
+        /* IPv6 */
+        struct sockaddr_in6 dest6;
+
+        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
+        if (req == NULL)
+        {
+            sirinet_stream_decref(siri.client);
+            sprintf(err_msg, "memory allocation error");
+            return -1;
+        }
+        log_debug(
+                "Trying to connect to '%s:%u'...",
+                adm_client->host,
+                adm_client->port);
+        uv_ip6_addr(adm_client->host, adm_client->port, &dest6);
+        uv_tcp_connect(
+                req,
+                (uv_tcp_t *) siri.client->stream,
+                (const struct sockaddr *) &dest6,
+                CLIENT_on_connect);
+    }
+    else
+    {
+        if (CLIENT_resolve_dns(
+                adm_client,
+                dns_req_family_map[siri.cfg->ip_support],
+                err_msg))
+        {
+            sirinet_stream_decref(siri.client);
+            return -1;  /* err_msg is set */
+        }
+    }
+    uv_timer_init(siri.loop, &siri.timer);
+    return 0;
+}
+
+/*
+ * Destroy the client request. (will be called when the socket is destroyed)
+ */
+void siri_service_client_free(siri_service_client_t * adm_client)
+{
+    if (adm_client != NULL)
+    {
+        sirinet_stream_decref(adm_client->client);
+        free(adm_client->host);
+        free(adm_client->username);
+        free(adm_client->password);
+        free(adm_client->dbname);
+        free(adm_client->dbpath);
+        free(adm_client);
+    }
+}
+/*
+ * Try to get an ip address from dns.
+ *
+ * This function should return 0 when we can start an attempt for discovering
+ * dns. When the result is not zero, CLIENT_on_resolved will not be called and
+ * err_msg is set.
+ */
+static int CLIENT_resolve_dns(
+        siri_service_client_t * adm_client,
+        int ai_family,
+        char * err_msg)
+{
+    struct addrinfo hints;
+    hints.ai_family = ai_family;
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_protocol = IPPROTO_TCP;
+    hints.ai_flags = AI_NUMERICSERV;
+
+    uv_getaddrinfo_t * resolver =
+            (uv_getaddrinfo_t *) malloc(sizeof(uv_getaddrinfo_t));
+
+    if (resolver == NULL)
+    {
+        sprintf(err_msg, "memory allocation error");
+        return -1;
+    }
+
+    int result;
+    resolver->data = adm_client;
+
+    char port[6]= {'\0'};
+    sprintf(port, "%u", adm_client->port);
+
+    result = uv_getaddrinfo(
+            siri.loop,
+            resolver,
+            (uv_getaddrinfo_cb) CLIENT_on_resolved,
+            adm_client->host,
+            port,
+            &hints);
+
+    if (result)
+    {
+        snprintf(
+                err_msg,
+                SIRI_MAX_SIZE_ERR_MSG,
+                "getaddrinfo call error %s",
+                uv_err_name(result));
+        free(resolver);
+    }
+
+    return result;
+}
+
+/*
+ * Callback used to check if resolving an ip address was successful.
+ */
+static void CLIENT_on_resolved(
+        uv_getaddrinfo_t * resolver,
+        int status,
+        struct addrinfo * res)
+{
+    siri_service_client_t * adm_client = (siri_service_client_t *) resolver->data;
+
+    if (status < 0)
+    {
+        CLIENT_err(
+                adm_client,
+                "cannot resolve ip address for '%s' (error: %s)",
+                adm_client->host,
+                uv_err_name(status));
+    }
+    else
+    {
+        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
+        if (req == NULL)
+        {
+            CLIENT_err(adm_client, "memory allocation error");
+        }
+        else
+        {
+            uv_tcp_connect(
+                    req,
+                    (uv_tcp_t *) siri.client->stream,
+                    (const struct sockaddr *) res->ai_addr,
+                    CLIENT_on_connect);
+        }
+    }
+
+    uv_freeaddrinfo(res);
+    free(resolver);
+}
+
+/*
+ * In case a client request fails, this function should be called to end
+ * the request. A package with the error message will be send to the client.
+ */
+static void CLIENT_err(
+        siri_service_client_t * adm_client,
+        const char * fmt,
+        ...)
+{
+    char err_msg[SIRI_MAX_SIZE_ERR_MSG];
+
+    va_list args;
+    va_start(args, fmt);
+    vsnprintf(err_msg, SIRI_MAX_SIZE_ERR_MSG, fmt, args);
+    va_end(args);
+
+    sirinet_pkg_t * package = sirinet_pkg_err(
+            adm_client->pid,
+            strlen(err_msg),
+            CPROTO_ERR_SERVICE,
+            err_msg);
+
+    if (package != NULL)
+    {
+        sirinet_pkg_send(adm_client->client, package);
+    }
+
+    log_error(err_msg);
+
+    if (~adm_client->flags & CLIENT_FLAGS_NO_ROLLBACK)
+    {
+        siri_service_request_rollback(adm_client->dbpath);
+    }
+
+    sirinet_stream_decref(siri.client);
+
+    uv_close((uv_handle_t *) &siri.timer, NULL);
+}
+
+/*
+ * Send a package to the 'other' SiriDB server. This function can be used for
+ * sending api requests for all database information required to create the
+ * database. Note that all packages are send with the same pid so packages
+ * should be send in sequence, not parallel.
+ *
+ * Note: pkg will be freed by calling this function.
+ */
+static void CLIENT_send_pkg(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    uv_write_t * req = (uv_write_t *) malloc(sizeof(uv_write_t));
+    if (req == NULL)
+    {
+        free(pkg);
+        CLIENT_err(adm_client, "memory allocation error");
+    }
+    req->data = adm_client;
+
+    adm_client->pkg = pkg;
+
+    /* set the correct check bit */
+    pkg->checkbit = pkg->tp ^ 255;
+
+    uv_timer_start(
+            &siri.timer,
+            CLIENT_request_timeout,
+            CLIENT_REQUEST_TIMEOUT,
+            0);
+
+    siri.timer.data = adm_client;
+
+    uv_buf_t wrbuf = uv_buf_init(
+            (char *) pkg,
+            sizeof(sirinet_pkg_t) + pkg->len);
+
+    uv_write(
+            req,
+            siri.client->stream,
+            &wrbuf,
+            1,
+            CLIENT_write_cb);
+}
+
+/*
+ * Write call-back.
+ */
+static void CLIENT_write_cb(uv_write_t * req, int status)
+{
+    siri_service_client_t * adm_client = (siri_service_client_t *)  req->data;
+
+    if (status)
+    {
+        uv_timer_stop(&siri.timer);
+        CLIENT_err(adm_client, "socket write error: %s", uv_strerror(status));
+    }
+
+    free(adm_client->pkg);
+    free(req);
+}
+
+/*
+ * Called when a connection to the 'other' siridb server is made.
+ * An authentication request will be send by user/password since this will be
+ * using the client connection. (a signal can be raised)
+ */
+static void CLIENT_on_connect(uv_connect_t * req, int status)
+{
+    sirinet_stream_t * client = req->handle->data;
+    siri_service_client_t * adm_client = client->origin;
+
+    if (status == 0)
+    {
+        log_debug(
+                "Connected to SiriDB server: '%s:%u', "
+                "sending authentication request",
+                adm_client->host, adm_client->port);
+
+        uv_read_start(
+                req->handle,
+                sirinet_stream_alloc_buffer,
+                sirinet_stream_on_data);
+
+        sirinet_pkg_t * pkg;
+        qp_packer_t * packer = sirinet_packer_new(512);
+
+        if (packer == NULL)
+        {
+            CLIENT_err(adm_client, "memory allocation error");
+        }
+        else
+        {
+            if (qp_add_type(packer, QP_ARRAY3) ||
+                qp_add_string(packer, adm_client->username) ||
+                qp_add_string(packer, adm_client->password) ||
+                qp_add_string(packer, adm_client->dbname))
+            {
+                qp_packer_free(packer);
+            }
+            else
+            {
+                pkg = sirinet_packer2pkg(packer, 0, CPROTO_REQ_AUTH);
+                CLIENT_send_pkg(adm_client, pkg);
+            }
+
+        }
+    }
+    else
+    {
+        CLIENT_err(
+                adm_client,
+                "connecting to server '%s:%u' failed with error: %s",
+                adm_client->host,
+                adm_client->port,
+                uv_strerror(status));
+    }
+    free(req);
+}
+
+/*
+ * on-data call-back function.
+ */
+static void CLIENT_on_data(sirinet_stream_t * client, sirinet_pkg_t * pkg)
+{
+    siri_service_client_t * adm_client = client->origin;
+    log_debug(
+            "Client response received (pid: %" PRIu16
+            ", len: %" PRIu32 ", tp: %s)",
+            pkg->pid,
+            pkg->len,
+            sirinet_cproto_server_str(pkg->tp));
+
+    if (adm_client->flags & CLIENT_FLAGS_TIMEOUT)
+    {
+        log_error("Client response received which was timed-out earlier");
+    }
+    else
+    {
+        uv_timer_stop(&siri.timer);
+
+        switch ((cproto_server_t) pkg->tp)
+        {
+        case CPROTO_RES_AUTH_SUCCESS:
+            CLIENT_on_auth_success(adm_client);
+            break;
+        case CPROTO_RES_QUERY:
+            switch (adm_client->request)
+            {
+            case CLIENT_REQUEST_STATUS:
+                CLIENT_on_request_status(adm_client, pkg);
+                break;
+            case CLIENT_REQUEST_POOLS:
+                CLIENT_on_request_pools(adm_client, pkg);
+                break;
+            default:
+                CLIENT_err(adm_client, "unexpected query response");
+            }
+            break;
+        case CPROTO_RES_FILE:
+            switch (adm_client->request)
+            {
+            case CLIENT_REQUEST_FILE_USERS:
+                CLIENT_on_file_users(adm_client, pkg);
+                break;
+            case CLIENT_REQUEST_FILE_GROUPS:
+                CLIENT_on_file_groups(adm_client, pkg);
+                break;
+            case CLIENT_REQUEST_FILE_SERVERS:
+                CLIENT_on_file_servers(adm_client, pkg);
+                break;
+            case CLIENT_REQUEST_FILE_DATABASE:
+                CLIENT_on_file_database(adm_client, pkg);
+                break;
+            default:
+                CLIENT_err(adm_client, "unexpected query response");
+            }
+            break;
+        case CPROTO_RES_ACK:
+            switch (adm_client->request)
+            {
+            case CLIENT_REQUEST_REGISTER_SERVER:
+                CLIENT_on_register_server(adm_client);
+                break;
+            default:
+                CLIENT_err(adm_client, "unexpected query response");
+            }
+            break;
+        case CPROTO_ERR_AUTH_CREDENTIALS:
+            CLIENT_err(
+                    adm_client,
+                    "invalid credentials for database '%s' on server '%s:%u'",
+                    adm_client->dbname,
+                    adm_client->host,
+                    adm_client->port);
+            break;
+        case CPROTO_ERR_AUTH_UNKNOWN_DB:
+            CLIENT_err(
+                    adm_client,
+                    "database '%s' does not exist on server '%s:%u'",
+                    adm_client->dbname,
+                    adm_client->host,
+                    adm_client->port);
+            break;
+        case CPROTO_ERR_MSG:
+        case CPROTO_ERR_QUERY:
+        case CPROTO_ERR_INSERT:
+        case CPROTO_ERR_SERVER:
+        case CPROTO_ERR_POOL:
+        case CPROTO_ERR_USER_ACCESS:
+            CLIENT_on_error_msg(adm_client, pkg);
+            break;
+        default:
+            CLIENT_err(
+                    adm_client,
+                    "unexpected response (%u) received from server '%s:%u'",
+                    pkg->tp,
+                    adm_client->host,
+                    adm_client->port);
+        }
+    }
+}
+
+/*
+ * Called when register server was successful.
+ */
+static void CLIENT_on_register_server(siri_service_client_t * adm_client)
+{
+    sirinet_pkg_t * package = sirinet_pkg_new(
+            adm_client->pid,
+            0,
+            CPROTO_ACK_SERVICE,
+            NULL);
+
+    if (package != NULL)
+    {
+        sirinet_pkg_send(adm_client->client, package);
+    }
+
+    log_info(
+            "Finished registering server on database '%s'",
+            adm_client->dbname);
+
+    sirinet_stream_decref(siri.client);
+    uv_close((uv_handle_t *) &siri.timer, NULL);
+}
+
+/*
+ * Called when database.dat is received.
+ */
+static void CLIENT_on_file_database(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    FILE * fp;
+    qp_unpacker_t unpacker;
+    qp_obj_t qp_uuid;
+    siridb_t * siridb;
+    int rc;
+    /* 13 = strlen("database.dat")+1  */
+    char fn[strlen(adm_client->dbpath) + 13];
+    sprintf(fn, "%sdatabase.dat", adm_client->dbpath);
+
+    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
+
+    if (qp_is_array(qp_next(&unpacker, NULL)) &&
+        /* schema check is not required at this moment but can be done here */
+        qp_next(&unpacker, NULL) == QP_INT64 &&
+        qp_next(&unpacker, &qp_uuid) == QP_RAW &&
+        qp_uuid.len == 16)
+    {
+        memcpy(unpacker.pt - 16, &adm_client->uuid, 16);
+    }
+    else
+    {
+        CLIENT_err(adm_client, "invalid database file received");
+        return;
+    }
+
+    fp = fopen(fn, "w");
+
+    if (fp == NULL)
+    {
+        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
+        return;
+    }
+
+    rc = fwrite(pkg->data, pkg->len, 1, fp);
+
+    if (fclose(fp) || rc != 1)
+    {
+        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
+        return;
+    }
+
+    siridb = siridb_new(adm_client->dbpath, LOCK_QUIT_IF_EXIST);
+
+    if (siridb == NULL)
+    {
+        CLIENT_err(adm_client, "error loading database");
+        return;
+    }
+
+    /* roll-back is not possible anymore */
+    adm_client->flags |= CLIENT_FLAGS_NO_ROLLBACK;
+
+    siridb->server->flags |= SERVER_FLAG_RUNNING;
+
+    /* Force one heart-beat */
+    siri_heartbeat_force();
+
+    sirinet_pkg_t * package;
+    qp_packer_t * packer = sirinet_packer_new(512);
+
+    if (packer == NULL)
+    {
+        CLIENT_err(adm_client, "memory allocation error");
+        return;
+    }
+
+    adm_client->request = CLIENT_REQUEST_REGISTER_SERVER;
+
+    if (qp_add_type(packer, QP_ARRAY4) ||
+        qp_add_raw(packer, (const unsigned char *) &adm_client->uuid, 16) ||
+        qp_add_string(packer, siri.cfg->server_address) ||
+        qp_add_int32(packer, (int32_t) siri.cfg->listen_backend_port) ||
+        qp_add_int32(packer, (int32_t) adm_client->pool))
+    {
+        qp_packer_free(packer);
+        CLIENT_err(adm_client, "memory allocation error");
+        return;
+    }
+
+    package = sirinet_packer2pkg(packer, 0, CPROTO_REQ_REGISTER_SERVER);
+    CLIENT_send_pkg(adm_client, package);
+}
+
+/*
+ * Called when servers.dat is received.
+ */
+static void CLIENT_on_file_servers(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    FILE * fp;
+    qp_unpacker_t unpacker;
+    qp_types_t tp;
+    int rc, n, close_num;
+    /* 12 = strlen("servers.dat") + 1  */
+    char fn[strlen(adm_client->dbpath) + 12];
+    sprintf(fn, "%sservers.dat", adm_client->dbpath);
+
+    fp = fopen(fn, "w");
+    if (fp == NULL)
+    {
+        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
+        return;
+    }
+
+    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
+    tp = qp_next(&unpacker, NULL);
+    if (tp >= QP_ARRAY0 && tp <= QP_ARRAY5)
+    {
+        pkg->data[0] = QP_ARRAY_OPEN;
+    }
+    else if (tp != QP_ARRAY_OPEN)
+    {
+        CLIENT_err(adm_client, "invalid server status response");
+        return;
+    }
+
+    /* schema checking is not required at this moment but can be done here */
+    qp_next(&unpacker, NULL);
+
+    tp = qp_next(&unpacker, NULL);
+
+    if (!qp_is_array(tp))
+    {
+        CLIENT_err(adm_client, "invalid server status response");
+        return;
+    }
+
+    close_num = (tp == QP_ARRAY_OPEN) ? 1 : 0;
+
+    /* trim closing */
+    for (n = pkg->len;
+         (unsigned char) pkg->data[n - 1] == QP_ARRAY_CLOSE;
+         n--);
+
+    rc = (fwrite(pkg->data, n, 1, fp) == 1) ? 0 : EOF;
+
+    if (close_num)
+    {
+        rc += qp_fadd_type(fp, QP_ARRAY_CLOSE);
+    }
+
+    rc += qp_fadd_type(fp, QP_ARRAY4);
+    rc += qp_fadd_raw(fp, (const unsigned char *) &adm_client->uuid, 16);
+    rc += qp_fadd_string(fp, siri.cfg->server_address);
+    rc += qp_fadd_int32(fp, (int32_t) siri.cfg->listen_backend_port);
+    rc += qp_fadd_int32(fp, (int32_t) adm_client->pool);
+    rc += fclose(fp);
+
+    if (rc)
+    {
+        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
+    }
+    else
+    {
+        sirinet_pkg_t * package;
+        adm_client->request = CLIENT_REQUEST_FILE_DATABASE;
+        package = sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_DATABASE, NULL);
+        if (package == NULL)
+        {
+            CLIENT_err(adm_client, "memory allocation error");
+        }
+        else
+        {
+            CLIENT_send_pkg(adm_client, package);
+        }
+    }
+}
+
+/*
+ * Called when groups.dat is received.
+ */
+static void CLIENT_on_file_groups(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    FILE * fp;
+    /* 11 = strlen("groups.dat") + 1  */
+    char fn[strlen(adm_client->dbpath) + 11];
+    sprintf(fn, "%sgroups.dat", adm_client->dbpath);
+
+    fp = fopen(fn, "w");
+    if (fp == NULL)
+    {
+        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
+    }
+    else
+    {
+        int rc = fwrite(pkg->data, pkg->len, 1, fp);
+
+        if (fclose(fp) || rc != 1)
+        {
+            CLIENT_err(adm_client, "cannot write data to file: %s", fn);
+        }
+        else
+        {
+            adm_client->request = CLIENT_REQUEST_FILE_SERVERS;
+            sirinet_pkg_t * package =
+                    sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_SERVERS, NULL);
+            if (package == NULL)
+            {
+                CLIENT_err(adm_client, "memory allocation error");
+            }
+            else
+            {
+                CLIENT_send_pkg(adm_client, package);
+            }
+        }
+    }
+}
+
+/*
+ * Called when users.dat is received.
+ */
+static void CLIENT_on_file_users(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    FILE * fp;
+    /* 10 = strlen("users.dat") + 1  */
+    char fn[strlen(adm_client->dbpath) + 10];
+    sprintf(fn, "%susers.dat", adm_client->dbpath);
+
+    fp = fopen(fn, "w");
+    if (fp == NULL)
+    {
+        CLIENT_err(adm_client, "cannot write or create file: %s", fn);
+    }
+    else
+    {
+        int rc = fwrite(pkg->data, pkg->len, 1, fp);
+
+        if (fclose(fp) || rc != 1)
+        {
+            CLIENT_err(adm_client, "cannot write data to file: %s", fn);
+        }
+        else
+        {
+            adm_client->request = CLIENT_REQUEST_FILE_GROUPS;
+            sirinet_pkg_t * package =
+                    sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_GROUPS, NULL);
+            if (package == NULL)
+            {
+                CLIENT_err(adm_client, "memory allocation error");
+            }
+            else
+            {
+                CLIENT_send_pkg(adm_client, package);
+            }
+        }
+    }
+}
+
+/*
+ * Called when 'list pools ...' response is received.
+ * This function will check which pool number will be assigned for a new pool
+ * or checks if a given pool for a new replica is valid.
+ */
+static void CLIENT_on_request_pools(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    qp_unpacker_t unpacker;
+    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
+    qp_obj_t qp_val;
+    qp_obj_t qp_pool;
+    qp_obj_t qp_servers;
+    int columns_found = 0;
+    int validate_pool = -1;
+
+    if (!qp_is_map(qp_next(&unpacker, NULL)))
+    {
+        CLIENT_err(adm_client, "invalid server status response");
+        return;
+    }
+
+    qp_next(&unpacker, &qp_val);
+
+    while (qp_val.tp == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_val.via.raw,
+                    "columns",
+                    qp_val.len) == 0 &&
+                qp_is_array(qp_next(&unpacker, NULL)) &&
+                qp_next(&unpacker, &qp_val) == QP_RAW &&
+                strncmp(
+                    (const char *) qp_val.via.raw, "pool", qp_val.len) == 0 &&
+                qp_next(&unpacker, &qp_val) == QP_RAW &&
+                strncmp(
+                    (const char *) qp_val.via.raw, "servers", qp_val.len) == 0)
+        {
+            if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
+            {
+                qp_next(&unpacker, &qp_val);
+            }
+            columns_found = 1;
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_val.via.raw, "pools", qp_val.len) == 0 &&
+                qp_is_array(qp_next(&unpacker, NULL)))
+        {
+            qp_next(&unpacker, &qp_val);
+
+            while (qp_is_array(qp_val.tp))
+            {
+                if (qp_next(&unpacker, &qp_pool) == QP_INT64 &&
+                    qp_next(&unpacker, &qp_servers) == QP_INT64)
+                {
+                    if (adm_client->pool < 0)
+                    {
+                        /* looking for a new pool */
+                        if (qp_pool.via.int64 > validate_pool)
+                        {
+                            validate_pool = qp_pool.via.int64;
+                        }
+                    }
+                    else
+                    {
+                        if (qp_pool.via.int64 == adm_client->pool)
+                        {
+                            if (qp_servers.via.int64 > 1)
+                            {
+                                CLIENT_err(
+                                        adm_client,
+                                        "pool %d has already %" PRId64
+                                        " servers",
+                                        adm_client->pool,
+                                        qp_servers.via.int64);
+                                return;
+                            }
+                            else
+                            {
+                                validate_pool = 0;
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    CLIENT_err(adm_client, "invalid server status response");
+                    return;
+                }
+                if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
+                {
+                    qp_next(&unpacker, &qp_val);
+                }
+            }
+            if (qp_val.tp == QP_ARRAY_CLOSE)
+            {
+                qp_next(&unpacker, &qp_val);
+            }
+            continue;
+        }
+
+        CLIENT_err(adm_client, "invalid server status response");
+        return;
+    }
+
+    if (!columns_found)
+    {
+        CLIENT_err(adm_client, "invalid server status response");
+    }
+    else
+    {
+        sirinet_pkg_t * package;
+
+        if (adm_client->pool < 0)
+        {
+            if (validate_pool == -1)
+            {
+                CLIENT_err(adm_client, "invalid server status response");
+                return;
+            }
+            /* set new correct pool in case we request a new pool */
+            adm_client->pool = validate_pool + 1;
+        }
+        else if (validate_pool == -1)
+        {
+            CLIENT_err(
+                    adm_client,
+                    "pool %d does not exist",
+                    adm_client->pool);
+            return;
+        }
+
+        adm_client->request = CLIENT_REQUEST_FILE_USERS;
+        package = sirinet_pkg_new(0, 0, CPROTO_REQ_FILE_USERS, NULL);
+        if (package == NULL)
+        {
+            CLIENT_err(adm_client, "memory allocation error");
+        }
+        else
+        {
+            CLIENT_send_pkg(adm_client, package);
+        }
+    }
+}
+
+/*
+ * Called when 'list servers ...' response is received.
+ * This function will check if each current server has status running.
+ * (this is a pre-check, the final register call does check for all servers
+ * to have the running status once more)
+ */
+static void CLIENT_on_request_status(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    qp_unpacker_t unpacker;
+    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
+    qp_obj_t qp_val;
+    qp_obj_t qp_name;
+    qp_obj_t qp_status;
+    qp_obj_t qp_version;
+    int columns_found = 0;
+    int servers_found = 0;
+    char version[MAX_VERSION_LEN];
+
+    if (!qp_is_map(qp_next(&unpacker, NULL)))
+    {
+        CLIENT_err(adm_client, "invalid server status response");
+        return;
+    }
+
+    qp_next(&unpacker, &qp_val);
+
+    while (qp_val.tp == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_val.via.raw,
+                    "columns",
+                    qp_val.len) == 0 &&
+                qp_is_array(qp_next(&unpacker, NULL)) &&
+                qp_next(&unpacker, &qp_val) == QP_RAW &&
+                strncmp(
+                    (const char *) qp_val.via.raw, "name", qp_val.len) == 0 &&
+                qp_next(&unpacker, &qp_val) == QP_RAW &&
+                strncmp(
+                    (const char *) qp_val.via.raw,
+                    "status",
+                    qp_val.len) == 0 &&
+                qp_next(&unpacker, &qp_val) == QP_RAW &&
+                strncmp(
+                    (const char *) qp_val.via.raw, "version", qp_val.len) == 0)
+        {
+            if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
+            {
+                qp_next(&unpacker, &qp_val);
+            }
+            columns_found = 1;
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_val.via.raw,
+                    "servers",
+                    qp_val.len) == 0 &&
+                qp_is_array(qp_next(&unpacker, NULL)))
+        {
+            qp_next(&unpacker, &qp_val);
+
+            while (qp_is_array(qp_val.tp))
+            {
+                if (qp_next(&unpacker, &qp_name) == QP_RAW &&
+                    qp_next(&unpacker, &qp_status) == QP_RAW &&
+                    qp_next(&unpacker, &qp_version) == QP_RAW &&
+                    qp_version.len < MAX_VERSION_LEN)
+                {
+                    /* copy and null terminate version */
+                    memcpy(version, qp_version.via.raw, qp_version.len);
+                    version[qp_version.len] = '\0';
+
+                    if (siri_version_cmp(version, SIRIDB_VERSION))
+                    {
+                        CLIENT_err(
+                                adm_client,
+                                "server '%.*s' is running on version %s "
+                                "while version %s is expected. (all SiriBD "
+                                "servers should run the same version)",
+                                (int) qp_name.len,
+                                qp_name.via.raw,
+                                version,
+                                SIRIDB_VERSION);
+                        return;
+                    }
+
+                    if (strncmp(
+                            (const char *) qp_status.via.raw,
+                            "running",
+                            qp_status.len) != 0)
+                    {
+                        CLIENT_err(
+                                adm_client,
+                                "server '%.*s' has status: '%.*s'",
+                                (int) qp_name.len,
+                                qp_name.via.raw,
+                                (int) qp_status.len,
+                                qp_status.via.raw);
+                        return;
+                    }
+                    servers_found++;
+                }
+                else
+                {
+                    CLIENT_err(adm_client, "invalid server status response");
+                    return;
+                }
+                if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
+                {
+                    qp_next(&unpacker, &qp_val);
+                }
+            }
+            if (qp_val.tp == QP_ARRAY_CLOSE)
+            {
+                qp_next(&unpacker, &qp_val);
+            }
+            continue;
+        }
+
+        CLIENT_err(adm_client, "invalid server status response");
+        return;
+    }
+
+    if (!servers_found || !columns_found)
+    {
+        CLIENT_err(adm_client, "invalid server status response");
+    }
+    else
+    {
+        sirinet_pkg_t * package;
+        qp_packer_t * packer = sirinet_packer_new(512);
+        if (packer == NULL)
+        {
+            CLIENT_err(adm_client, "memory allocation error");
+        }
+        else
+        {
+            adm_client->request = CLIENT_REQUEST_POOLS;
+
+            /* no need to check since this will always fit */
+            qp_add_type(packer, QP_ARRAY1);
+            qp_add_string(packer, "list pools pool, servers");
+            package = sirinet_packer2pkg(packer, 0, CPROTO_REQ_QUERY);
+            CLIENT_send_pkg(adm_client, package);
+        }
+    }
+}
+
+/*
+ * Called when an error message is received.
+ */
+static void CLIENT_on_error_msg(
+        siri_service_client_t * adm_client,
+        sirinet_pkg_t * pkg)
+{
+    qp_unpacker_t unpacker;
+    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
+    qp_obj_t qp_err;
+
+    if (qp_is_map(qp_next(&unpacker, NULL)) &&
+        qp_next(&unpacker, NULL) == QP_RAW &&
+        qp_next(&unpacker, &qp_err) == QP_RAW)
+    {
+        CLIENT_err(
+                adm_client,
+                "error on server '%s:%u': %.*s",
+                adm_client->host,
+                adm_client->port,
+                (int) qp_err.len,
+                qp_err.via.raw);
+    }
+    else
+    {
+        CLIENT_err(
+                adm_client,
+                "unexpected error on server '%s:%u'",
+                adm_client->host,
+                adm_client->port);
+    }
+}
+
+/*
+ * Called when authentication is successful.
+ */
+static void CLIENT_on_auth_success(siri_service_client_t * adm_client)
+{
+    sirinet_pkg_t * pkg;
+    qp_packer_t * packer = sirinet_packer_new(512);
+    if (packer == NULL)
+    {
+        CLIENT_err(adm_client, "memory allocation error");
+    }
+    else
+    {
+        adm_client->request = CLIENT_REQUEST_STATUS;
+
+        /* no need to check since this will always fit */
+        qp_add_type(packer, QP_ARRAY1);
+        qp_add_string(packer, "list servers name, status, version");
+        pkg = sirinet_packer2pkg(packer, 0, CPROTO_REQ_QUERY);
+        CLIENT_send_pkg(adm_client, pkg);
+    }
+}
+
+/*
+ * Timeout on a client request.
+ */
+static void CLIENT_request_timeout(uv_timer_t * handle)
+{
+    siri_service_client_t * adm_client = (siri_service_client_t *) handle->data;
+
+    adm_client->flags |= CLIENT_FLAGS_TIMEOUT;
+
+    CLIENT_err(adm_client, "request timeout");
+}
diff --git a/src/siri/service/request.c b/src/siri/service/request.c
new file mode 100644 (file)
index 0000000..d4391bf
--- /dev/null
@@ -0,0 +1,989 @@
+/*
+ * request.c - SiriDB Service Request.
+ */
+#define PCRE2_CODE_UNIT_WIDTH 8
+
+#include <siri/service/account.h>
+#include <siri/service/client.h>
+#include <stddef.h>
+#include <siri/service/request.h>
+#include <siri/siri.h>
+#include <logger/logger.h>
+#include <pcre2.h>
+#include <lock/lock.h>
+#include <xmath/xmath.h>
+#include <unistd.h>
+#include <uuid/uuid.h>
+#include <siri/db/server.h>
+#include <siri/db/buffer.h>
+#include <siri/version.h>
+#include <siri/db/reindex.h>
+
+#define DEFAULT_TIME_PRECISION 1
+#define DEFAULT_BUFFER_SIZE 1024
+#define DEFAULT_DURATION_NUM 604800
+#define DEFAULT_DURATION_LOG 86400
+#define DB_CONF_FN "database.conf"
+#define DB_DAT_FN "database.dat"
+#define DEFAULT_CONF \
+"#\n" \
+"# Welcome to the SiriDB configuration file\n" \
+"#\n" \
+"\n" \
+"[buffer]\n" \
+"# Alternative path to save the buffer file.\n" \
+"# In case you later plan to change this location you manually need to move\n" \
+"# the buffer file to the new location.\n" \
+"# path = <buffer_path>\n" \
+"\n" \
+"# Buffer size in bytes. This size must be a multiple of 512 with a maximum\n" \
+"# of 1048576 bytes. Be careful using large values since SiriDB will require\n" \
+"# memory based on this value. A value between 1024 and 32768 is recommended.\n" \
+"# size = 1024\n"
+
+#define CHECK_DBNAME_AND_CREATE_PATH                                        \
+    pcre_exec_ret = pcre2_match(                                            \
+            siri.dbname_regex,                                              \
+            (PCRE2_SPTR8) qp_dbname.via.raw,                                \
+            qp_dbname.len,                                                  \
+            0,                                                              \
+            0,                                                              \
+            siri.dbname_match_data,                                         \
+            NULL);                                                          \
+                                                                            \
+    if (pcre_exec_ret < 0)                                                  \
+    {                                                                       \
+        snprintf(                                                           \
+                err_msg,                                                    \
+                SIRI_MAX_SIZE_ERR_MSG,                                      \
+                "invalid database name: '%.*s'",                            \
+                (int) qp_dbname.len,                                        \
+                qp_dbname.via.raw);                                         \
+        return CPROTO_ERR_SERVICE;                                            \
+    }                                                                       \
+                                                                            \
+    if (llist_get(                                                          \
+            siri.siridb_list,                                               \
+            (llist_cb) SERVICE_find_database,                                 \
+            &qp_dbname) != NULL)                                            \
+    {                                                                       \
+        snprintf(                                                           \
+                err_msg,                                                    \
+                SIRI_MAX_SIZE_ERR_MSG,                                      \
+                "database name already exists: '%.*s'",                     \
+                (int) qp_dbname.len,                                        \
+                qp_dbname.via.raw);                                         \
+        return CPROTO_ERR_SERVICE;                                            \
+    }                                                                       \
+                                                                            \
+    dbpath_len = strlen(siri.cfg->default_db_path) + qp_dbname.len + 2;     \
+    char dbpath[dbpath_len];                                                \
+    sprintf(dbpath,                                                         \
+            "%s%.*s/",                                                      \
+            siri.cfg->default_db_path,                                      \
+            (int) qp_dbname.len,                                            \
+            qp_dbname.via.raw);                                             \
+                                                                            \
+    if (stat(dbpath, &st) != -1)                                            \
+    {                                                                       \
+        snprintf(                                                           \
+                err_msg,                                                    \
+                SIRI_MAX_SIZE_ERR_MSG,                                      \
+                "database directory already exists: %s",                    \
+                dbpath);                                                    \
+        return CPROTO_ERR_SERVICE;                                            \
+    }                                                                       \
+                                                                            \
+    if (mkdir(dbpath, 0700) == -1)                                          \
+    {                                                                       \
+        snprintf(                                                           \
+                err_msg,                                                    \
+                SIRI_MAX_SIZE_ERR_MSG,                                      \
+                "cannot create directory: %s",                              \
+                dbpath);                                                    \
+        return CPROTO_ERR_SERVICE;                                            \
+    }                                                                       \
+                                                                            \
+    char dbfn[dbpath_len + max_filename_sz];                                \
+    sprintf(dbfn, "%s%s", dbpath, DB_CONF_FN);                              \
+                                                                            \
+    fp = fopen(dbfn, "w");                                                  \
+    if (fp == NULL)                                                         \
+    {                                                                       \
+        siri_service_request_rollback(dbpath);                                \
+        snprintf(                                                           \
+                err_msg,                                                    \
+                SIRI_MAX_SIZE_ERR_MSG,                                      \
+                "cannot open file for writing: %s",                         \
+                dbfn);                                                      \
+        return CPROTO_ERR_SERVICE;                                            \
+    }                                                                       \
+                                                                            \
+    rc = fputs(DEFAULT_CONF, fp);                                           \
+                                                                            \
+    if (fclose(fp) || rc < 0)                                               \
+    {                                                                       \
+        siri_service_request_rollback(dbpath);                                \
+        snprintf(                                                           \
+                err_msg,                                                    \
+                SIRI_MAX_SIZE_ERR_MSG,                                      \
+                "cannot write file: %s",                                    \
+                dbfn);                                                      \
+        return CPROTO_ERR_SERVICE;                                            \
+    }
+
+static cproto_server_t SERVICE_on_new_account(
+        qp_unpacker_t * qp_unpacker,
+        char * err_msg);
+static cproto_server_t SERVICE_on_change_password(
+        qp_unpacker_t * qp_unpacker,
+        char * err_msg);
+static cproto_server_t SERVICE_on_drop_account(
+        qp_unpacker_t * qp_unpacker,
+        qp_obj_t * qp_account,
+        char * err_msg);
+static cproto_server_t SERVICE_on_new_database(
+        qp_unpacker_t * qp_unpacker,
+        char * err_msg);
+static cproto_server_t SERVICE_on_new_replica_or_pool(
+        qp_unpacker_t * qp_unpacker,
+        uint16_t pid,
+        sirinet_stream_t * client,
+        int req,
+        char * err_msg);
+static cproto_server_t SERVICE_on_get_version(
+        qp_unpacker_t * qp_unpacker,
+        qp_packer_t ** packaddr,
+        char * err_msg);
+static cproto_server_t SERVICE_on_get_accounts(
+        qp_unpacker_t * qp_unpacker,
+        qp_packer_t ** packaddr,
+        char * err_msg);
+static cproto_server_t SERVICE_on_get_databases(
+        qp_unpacker_t * qp_unpacker,
+        qp_packer_t ** packaddr,
+        char * err_msg);
+static int8_t SERVICE_time_precision(qp_obj_t * qp_time_precision);
+static int64_t SERVICE_duration(qp_obj_t * qp_duration, uint8_t time_precision);
+static int SERVICE_list_databases(siridb_t * siridb, qp_packer_t * packer);
+static int SERVICE_find_database(siridb_t * siridb, qp_obj_t * dbname);
+static int SERVICE_list_accounts(
+        siri_service_account_t * account,
+        qp_packer_t * packer);
+
+static size_t max_filename_sz;
+
+/*
+ * Initialize service requests. (called once when initializing SiriDB)
+ */
+int siri_service_request_init(void)
+{
+    max_filename_sz = xmath_max_size(
+            3,
+            strlen(DB_CONF_FN),
+            strlen(DB_DAT_FN),
+            strlen(REINDEX_FN));
+
+    int pcre_error_num;
+    PCRE2_SIZE pcre_error_offset;
+
+    pcre2_code * regex;
+    pcre2_match_data * match_data;
+
+    regex = pcre2_compile(
+                (PCRE2_SPTR8) "^[a-zA-Z][a-zA-Z0-9-_]{0,18}[a-zA-Z0-9]$",
+                PCRE2_ZERO_TERMINATED,
+                0,
+                &pcre_error_num,
+                &pcre_error_offset,
+                NULL);
+    if (regex == NULL)
+    {
+        return -1;
+    }
+    match_data = pcre2_match_data_create_from_pattern(regex, NULL);
+
+    if(match_data == NULL)
+    {
+        pcre2_match_data_free(match_data);
+        pcre2_code_free(regex);
+        return -1;
+    }
+
+    siri.dbname_regex = regex;
+    siri.dbname_match_data = match_data;
+
+    return 0;
+}
+
+/*
+ * Destroy service requests. (only called when exiting SiriDB)
+ */
+void siri_service_request_destroy(void)
+{
+    pcre2_match_data_free(siri.dbname_match_data);
+    pcre2_code_free(siri.dbname_regex);
+}
+
+/*
+ * Returns CPROTO_ACK_SERVICE or CPROTO_DEFERRED when successful.
+ * In case of an error CPROTO_ERR_SERVICE can be returned in which case err_msg
+ * is set, or CPROTO_ERR_SERVICE_INVALID_REQUEST is returned.
+ */
+cproto_server_t siri_service_request(
+        int tp,
+        qp_unpacker_t * qp_unpacker,
+        qp_obj_t * qp_account,
+        qp_packer_t ** packaddr,
+        uint16_t pid,
+        sirinet_stream_t * client,
+        char * err_msg)
+{
+    switch ((service_request_t) tp)
+    {
+    case SERVICE_NEW_ACCOUNT_:
+        return SERVICE_on_new_account(qp_unpacker, err_msg);
+    case SERVICE_CHANGE_PASSWORD_:
+        return SERVICE_on_change_password(qp_unpacker, err_msg);
+    case SERVICE_DROP_ACCOUNT_:
+        return SERVICE_on_drop_account(qp_unpacker, qp_account, err_msg);
+    case SERVICE_NEW_DATABASE_:
+        return SERVICE_on_new_database(qp_unpacker, err_msg);
+    case SERVICE_NEW_POOL:
+        return SERVICE_on_new_replica_or_pool(
+                qp_unpacker,
+                pid,
+                client,
+                SERVICE_NEW_POOL,
+                err_msg);
+    case SERVICE_NEW_REPLICA:
+        return SERVICE_on_new_replica_or_pool(
+                qp_unpacker,
+                pid,
+                client,
+                SERVICE_NEW_REPLICA,
+                err_msg);
+    case SERVICE_GET_VERSION:
+        return SERVICE_on_get_version(qp_unpacker, packaddr, err_msg);
+    case SERVICE_GET_ACCOUNTS:
+        return SERVICE_on_get_accounts(qp_unpacker, packaddr, err_msg);
+    case SERVICE_GET_DATABASES:
+        return SERVICE_on_get_databases(qp_unpacker, packaddr, err_msg);
+    default:
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+}
+
+/*
+ * Returns CPROTO_ACK_SERVICE when successful.
+ * In case of an error CPROTO_ERR_SERVICE can be returned in which case err_msg
+ * is set, or CPROTO_ERR_SERVICE_INVALID_REQUEST is returned.
+ */
+static cproto_server_t SERVICE_on_new_account(
+        qp_unpacker_t * qp_unpacker,
+        char * err_msg)
+{
+    qp_obj_t qp_key, qp_account, qp_password;
+
+    qp_account.tp = QP_HOOK;
+    qp_password.tp = QP_HOOK;
+
+    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "account",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_account) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "password",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_password) == QP_RAW)
+        {
+            continue;
+        }
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_account.tp == QP_HOOK || qp_password.tp == QP_HOOK)
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    return (siri_service_account_new(
+            &siri,
+            &qp_account,
+            &qp_password,
+            0,
+            err_msg) ||
+            siri_service_account_save(&siri, err_msg)) ?
+                    CPROTO_ERR_SERVICE : CPROTO_ACK_SERVICE;
+}
+
+/*
+ * Returns CPROTO_ACK_SERVICE when successful.
+ * In case of an error CPROTO_ERR_SERVICE can be returned in which case err_msg
+ * is set, or CPROTO_ERR_SERVICE_INVALID_REQUEST is returned.
+ */
+static cproto_server_t SERVICE_on_change_password(
+        qp_unpacker_t * qp_unpacker,
+        char * err_msg)
+{
+    qp_obj_t qp_key, qp_account, qp_password;
+
+    qp_account.tp = QP_HOOK;
+    qp_password.tp = QP_HOOK;
+
+    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "account",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_account) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "password",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_password) == QP_RAW)
+        {
+            continue;
+        }
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_account.tp == QP_HOOK || qp_password.tp == QP_HOOK)
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    return (siri_service_account_change_password(
+            &siri,
+            &qp_account,
+            &qp_password,
+            err_msg) ||
+            siri_service_account_save(&siri, err_msg)) ?
+                    CPROTO_ERR_SERVICE : CPROTO_ACK_SERVICE;
+}
+
+/*
+ * Returns CPROTO_ACK_SERVICE when successful.
+ * In case of an error CPROTO_ERR_SERVICE can be returned in which case err_msg
+ * is set, or CPROTO_ERR_SERVICE_INVALID_REQUEST is returned.
+ */
+static cproto_server_t SERVICE_on_drop_account(
+        qp_unpacker_t * qp_unpacker,
+        qp_obj_t * qp_account,
+        char * err_msg)
+{
+    qp_obj_t qp_key, qp_target;
+
+    qp_target.tp = QP_HOOK;
+
+    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "account",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_target) == QP_RAW)
+        {
+            continue;
+        }
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_target.tp == QP_HOOK)
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_target.len == qp_account->len &&
+        strncmp(
+            (const char *) qp_target.via.raw,
+            (const char *) qp_account->via.raw,
+            qp_target.len) == 0)
+    {
+        sprintf(err_msg, "cannot drop your own account");
+        return CPROTO_ERR_SERVICE;
+    }
+
+    return (siri_service_account_drop(
+            &siri,
+            &qp_target,
+            err_msg) ||
+            siri_service_account_save(&siri, err_msg)) ?
+                    CPROTO_ERR_SERVICE : CPROTO_ACK_SERVICE;
+}
+
+/*
+ * Returns CPROTO_ACK_SERVICE when successful.
+ * In case of an error CPROTO_ERR_SERVICE can be returned in which case err_msg
+ * is set, or CPROTO_ERR_SERVICE_INVALID_REQUEST is returned.
+ */
+static cproto_server_t SERVICE_on_new_database(
+        qp_unpacker_t * qp_unpacker,
+        char * err_msg)
+{
+    FILE * fp;
+    qp_obj_t
+        qp_key,
+        qp_dbname,
+        qp_time_precision,
+        qp_buffer_size,
+        qp_duration_num,
+        qp_duration_log;
+    size_t dbpath_len;
+    int pcre_exec_ret;
+    int rc;
+    struct stat st;
+    int8_t time_precision;
+    int64_t buffer_size, duration_num, duration_log;
+    siridb_t * siridb;
+    uuid_t uuid;
+
+    memset(&st, 0, sizeof(struct stat));
+
+    if (siri.siridb_list->len == MAX_NUMBER_DB)
+    {
+        sprintf(err_msg,
+                "maximum number of databases is reached (%zd)",
+                siri.siridb_list->len);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    qp_dbname.tp = QP_HOOK;
+    qp_time_precision.tp = QP_HOOK;
+    qp_buffer_size.tp = QP_HOOK;
+    qp_duration_num.tp = QP_HOOK;
+    qp_duration_log.tp = QP_HOOK;
+
+    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "dbname",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_dbname) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "time_precision",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_time_precision) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "buffer_size",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_buffer_size) == QP_INT64)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "duration_num",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_duration_num) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "duration_log",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_duration_log) == QP_RAW)
+        {
+            continue;
+        }
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_dbname.tp == QP_HOOK)
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    time_precision = (qp_time_precision.tp == QP_HOOK) ?
+            DEFAULT_TIME_PRECISION : SERVICE_time_precision(&qp_time_precision);
+    if (time_precision == -1)
+    {
+        snprintf(
+                err_msg,
+                SIRI_MAX_SIZE_ERR_MSG,
+                "invalid time precision: '%.*s' (expecting s, ms, us or ns)",
+                (int) qp_time_precision.len,
+                qp_time_precision.via.raw);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    duration_num = (qp_duration_num.tp == QP_HOOK) ?
+            DEFAULT_DURATION_NUM * xmath_ipow(1000, time_precision):
+            SERVICE_duration(&qp_duration_num, time_precision);
+
+    if (duration_num == -1)
+    {
+        snprintf(
+                err_msg,
+                SIRI_MAX_SIZE_ERR_MSG,
+                "invalid number duration: '%.*s' "
+                "(valid examples: 6h, 2d or 1w)",
+                (int) qp_duration_num.len,
+                qp_duration_num.via.raw);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    duration_log = (qp_duration_log.tp == QP_HOOK) ?
+            DEFAULT_DURATION_LOG * xmath_ipow(1000, time_precision):
+            SERVICE_duration(&qp_duration_log, time_precision);
+
+    if (duration_log == -1)
+    {
+        snprintf(
+                err_msg,
+                SIRI_MAX_SIZE_ERR_MSG,
+                "invalid log duration: '%.*s' "
+                "(valid examples: 6h, 2d or 1w)",
+                (int) qp_duration_log.len,
+                qp_duration_log.via.raw);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    buffer_size = (qp_buffer_size.tp == QP_HOOK) ?
+            DEFAULT_BUFFER_SIZE : qp_buffer_size.via.int64;
+
+    if (!siridb_buffer_is_valid_size(buffer_size))
+    {
+        sprintf(err_msg,
+                "invalid buffer size: %" PRId64
+                " (expecting a multiple of 512 with a maximum of %" PRId64 ")",
+                buffer_size,
+                (int64_t) MAX_BUFFER_SZ);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    CHECK_DBNAME_AND_CREATE_PATH
+
+    sprintf(dbfn, "%s%s", dbpath, DB_DAT_FN);
+    fp = qp_open(dbfn, "w");
+    if (fp == NULL)
+    {
+        siri_service_request_rollback(dbpath);
+        snprintf(
+                err_msg,
+                SIRI_MAX_SIZE_ERR_MSG,
+                "cannot open file for writing: %s",
+                dbfn);
+        return CPROTO_ERR_SERVICE;
+    }
+    rc = 0;
+    uuid_generate(uuid);
+
+    if (qp_fadd_type(fp, QP_ARRAY_OPEN) ||
+        qp_fadd_int8(fp, SIRIDB_SCHEMA) ||
+        qp_fadd_raw(fp, (const unsigned char *) uuid, 16) ||
+        qp_fadd_raw(fp, qp_dbname.via.raw, qp_dbname.len) ||
+        qp_fadd_int8(fp, time_precision) ||
+        qp_fadd_int64(fp, buffer_size) ||
+        qp_fadd_int64(fp, duration_num) ||
+        qp_fadd_int64(fp, duration_log) ||
+        qp_fadd_string(fp, "NAIVE") ||
+        qp_fadd_double(fp, DEF_DROP_THRESHOLD) ||
+        qp_fadd_int64(fp, DEF_SELECT_POINTS_LIMIT) ||
+        qp_fadd_int64(fp, DEF_LIST_LIMIT) ||
+        qp_fadd_type(fp, QP_ARRAY_CLOSE))
+    {
+        rc = -1;
+    }
+
+    if (qp_close(fp) || rc == -1)
+    {
+        siri_service_request_rollback(dbpath);
+        snprintf(
+                err_msg,
+                SIRI_MAX_SIZE_ERR_MSG,
+                "cannot write file: %s",
+                dbfn);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    siridb = siridb_new(dbpath, LOCK_QUIT_IF_EXIST);
+    if (siridb == NULL)
+    {
+        siri_service_request_rollback(dbpath);
+        sprintf(err_msg, "error loading database");
+        return CPROTO_ERR_SERVICE;
+    }
+
+    siridb->server->flags |= SERVER_FLAG_RUNNING;
+
+    /* Force one heart-beat */
+    siri_heartbeat_force();
+
+    return CPROTO_ACK_SERVICE;
+}
+
+/*
+ * Returns CPROTO_DEFERRED when successful.
+ * In case of an error CPROTO_ERR_SERVICE can be returned in which case err_msg
+ * is set, or CPROTO_ERR_SERVICE_INVALID_REQUEST is returned.
+ */
+static cproto_server_t SERVICE_on_new_replica_or_pool(
+        qp_unpacker_t * qp_unpacker,
+        uint16_t pid,
+        sirinet_stream_t * client,
+        int req,
+        char * err_msg)
+{
+    FILE * fp;
+    qp_obj_t
+        qp_key,
+        qp_dbname,
+        qp_pool,
+        qp_host,
+        qp_port,
+        qp_username,
+        qp_password;
+    size_t dbpath_len;
+    int pcre_exec_ret;
+    int rc;
+    struct stat st;
+    uint16_t port;
+    uuid_t uuid;
+
+    memset(&st, 0, sizeof(struct stat));
+
+    if (siri.siridb_list->len == MAX_NUMBER_DB)
+    {
+        sprintf(err_msg,
+                "maximum number of databases is reached (%zd)",
+                siri.siridb_list->len);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    qp_dbname.tp = QP_HOOK;
+    qp_pool.tp = QP_HOOK;
+    qp_host.tp = QP_HOOK;
+    qp_port.tp = QP_HOOK;
+    qp_username.tp = QP_HOOK;
+    qp_password.tp = QP_HOOK;
+
+    if (!qp_is_map(qp_next(qp_unpacker, NULL)))
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    while (qp_next(qp_unpacker, &qp_key) == QP_RAW)
+    {
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "dbname",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_dbname) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw, "pool", qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_pool) == QP_INT64)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw, "host", qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_host) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw, "port", qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_port) == QP_INT64)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "username",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_username) == QP_RAW)
+        {
+            continue;
+        }
+        if (    strncmp(
+                    (const char *) qp_key.via.raw,
+                    "password",
+                    qp_key.len) == 0 &&
+                qp_next(qp_unpacker, &qp_password) == QP_RAW)
+        {
+            continue;
+        }
+
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_dbname.tp == QP_HOOK ||
+        (
+            (req == SERVICE_NEW_POOL && qp_pool.tp != QP_HOOK) ||
+            (req == SERVICE_NEW_REPLICA && qp_pool.tp == QP_HOOK)
+        ) ||
+        qp_host.tp == QP_HOOK ||
+        qp_port.tp == QP_HOOK ||
+        qp_username.tp == QP_HOOK ||
+        qp_password.tp == QP_HOOK)
+    {
+        return CPROTO_ERR_SERVICE_INVALID_REQUEST;
+    }
+
+    if (qp_port.via.int64 < 1 || qp_port.via.int64 > 65535)
+    {
+        sprintf(err_msg,
+                "invalid port number: %" PRId64
+                " (expecting a value between 0 and 65536)",
+                qp_port.via.int64);
+        return CPROTO_ERR_SERVICE;
+    }
+
+    port = (uint16_t) qp_port.via.int64;
+    uuid_generate(uuid);
+
+    CHECK_DBNAME_AND_CREATE_PATH
+
+    if (req == SERVICE_NEW_POOL)
+    {
+        sprintf(dbfn, "%s%s", dbpath, REINDEX_FN);
+        fp = fopen(dbfn, "w");
+        if (fp == NULL || fclose(fp))
+        {
+            siri_service_request_rollback(dbpath);
+            snprintf(
+                    err_msg,
+                    SIRI_MAX_SIZE_ERR_MSG,
+                    "cannot open file for writing: %s",
+                    dbfn);
+            return CPROTO_ERR_SERVICE;
+        }
+    }
+
+    if (siri_service_client_request(
+            pid,
+            port,
+            /* -1 = new pool  */
+            (req == SERVICE_NEW_POOL) ? -1 : qp_pool.via.int64,
+            &uuid,
+            &qp_host,
+            &qp_username,
+            &qp_password,
+            &qp_dbname,
+            dbpath,
+            client,
+            err_msg))
+    {
+        siri_service_request_rollback(dbpath);
+        return CPROTO_ERR_SERVICE;
+    }
+    return CPROTO_DEFERRED;
+}
+
+/*
+ * Returns CPROTO_ACK_SERVICE_DATA when successful.
+ * In case of an error CPROTO_ERR_SERVICE will be returned and err_msg is set
+ */
+static cproto_server_t SERVICE_on_get_version(
+        qp_unpacker_t * qp_unpacker __attribute__((unused)),
+        qp_packer_t ** packaddr,
+        char * err_msg)
+{
+    qp_packer_t * packer = sirinet_packer_new(128);
+    if (packer != NULL)
+    {
+        if (!qp_add_type(packer, QP_ARRAY_OPEN) &&
+            !qp_add_string(packer, SIRIDB_VERSION))
+        {
+            *packaddr = packer;
+            return CPROTO_ACK_SERVICE_DATA;
+        }
+
+        /* error, free packer */
+        qp_packer_free(packer);
+    }
+    sprintf(err_msg, "memory allocation error");
+    return CPROTO_ERR_SERVICE;
+}
+
+static cproto_server_t SERVICE_on_get_accounts(
+        qp_unpacker_t * qp_unpacker __attribute__((unused)),
+        qp_packer_t ** packaddr,
+        char * err_msg)
+{
+    qp_packer_t * packer = sirinet_packer_new(128);
+
+    if (packer != NULL)
+    {
+        qp_add_type(packer, QP_ARRAY_OPEN);
+
+        if (!llist_walk(
+                siri.accounts,
+                (llist_cb) SERVICE_list_accounts,
+                packer))
+        {
+            *packaddr = packer;
+            return CPROTO_ACK_SERVICE_DATA;
+        }
+
+        /* error, free packer */
+        qp_packer_free(packer);
+    }
+    sprintf(err_msg, "memory allocation error");
+    return CPROTO_ERR_SERVICE;
+}
+
+static cproto_server_t SERVICE_on_get_databases(
+        qp_unpacker_t * qp_unpacker __attribute__((unused)),
+        qp_packer_t ** packaddr,
+        char * err_msg)
+{
+    qp_packer_t * packer = sirinet_packer_new(128);
+
+    if (packer != NULL)
+    {
+        qp_add_type(packer, QP_ARRAY_OPEN);
+
+        if (!llist_walk(
+                siri.siridb_list,
+                (llist_cb) SERVICE_list_databases,
+                packer))
+        {
+            *packaddr = packer;
+            return CPROTO_ACK_SERVICE_DATA;
+        }
+
+        /* error, free packer */
+        qp_packer_free(packer);
+    }
+    sprintf(err_msg, "memory allocation error");
+    return CPROTO_ERR_SERVICE;
+}
+
+void siri_service_request_rollback(const char * dbpath)
+{
+    size_t dbpath_len = strlen(dbpath);
+    char dbfn[dbpath_len + max_filename_sz];
+
+    sprintf(dbfn, "%s%s", dbpath, DB_CONF_FN);
+    unlink(dbfn);
+    sprintf(dbfn, "%s%s", dbpath, DB_DAT_FN);
+    unlink(dbfn);
+    sprintf(dbfn, "%s%s", dbpath, REINDEX_FN);
+    unlink(dbfn);
+    if (rmdir(dbpath))
+    {
+        log_error("Roll-back creating new database has failed.");
+    }
+}
+
+static int8_t SERVICE_time_precision(qp_obj_t * qp_time_precision)
+{
+    if (qp_time_precision->tp != QP_RAW)
+    {
+        return -1;
+    }
+    if (qp_time_precision->len == 1 && qp_time_precision->via.raw[0] == 's')
+    {
+        return 0;
+    }
+    else if (qp_time_precision->len == 2 && qp_time_precision->via.raw[1] == 's')
+    {
+        switch (qp_time_precision->via.raw[0])
+        {
+        case 'm': return 1;
+        case 'u': return 2;
+        case 'n': return 3;
+        }
+    }
+    return -1;
+}
+
+static int64_t SERVICE_duration(qp_obj_t * qp_duration, uint8_t time_precision)
+{
+    char * endptr;
+    long int val;
+
+    if (qp_duration->tp != QP_RAW || qp_duration->len < 2)
+    {
+        return -1;
+    }
+
+    val = strtol((const char *) qp_duration->via.raw, &endptr, 10);
+
+    if (val < 1 || val > 99 || endptr == (const char *) qp_duration->via.raw)
+    {
+        return -1;
+    }
+
+    if (endptr != (const char *) qp_duration->via.raw + (qp_duration->len - 1))
+    {
+        return -1;
+    }
+
+    switch (*endptr)
+    {
+    case 'h': return xmath_ipow(1000, time_precision) * val * 3600;
+    case 'd': return xmath_ipow(1000, time_precision) * val * 86400;
+    case 'w': return xmath_ipow(1000, time_precision) * val * 604800;
+    }
+
+    return -1;
+}
+
+static int SERVICE_list_databases(siridb_t * siridb, qp_packer_t * packer)
+{
+    return qp_add_string(packer, siridb->dbname);
+}
+
+static int SERVICE_find_database(siridb_t * siridb, qp_obj_t * dbname)
+{
+    return (
+        strlen(siridb->dbname) == dbname->len &&
+        strncmp(
+            siridb->dbname,
+            (const char *) dbname->via.raw,
+            dbname->len) == 0);
+}
+
+static int SERVICE_list_accounts(
+        siri_service_account_t * account,
+        qp_packer_t * packer)
+{
+    return qp_add_string(packer, account->account);
+}
index 683e08f3d33ee27fc84348242370116116221158..11e42256ab8781129d70448a07b6ac2fd738101e 100644 (file)
@@ -1,12 +1,6 @@
 /*
- * siri.h - global methods for SiriDB.
+ * siri.c - Root for SiriDB.
  *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
  *
  * Info siri->siridb_mutex:
  *
@@ -23,8 +17,8 @@
 #include <assert.h>
 #include <logger/logger.h>
 #include <qpack/qpack.h>
-#include <siri/admin/account.h>
-#include <siri/admin/request.h>
+#include <siri/service/account.h>
+#include <siri/service/request.h>
 #include <siri/async.h>
 #include <siri/buffersync.h>
 #include <siri/cfg/cfg.h>
@@ -48,7 +42,7 @@
 #include <siri/version.h>
 #include <stddef.h>
 #include <stdio.h>
-#include <strextra/strextra.h>
+#include <xstr/xstr.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <time.h>
@@ -114,7 +108,7 @@ void siri_setup_logger(void)
     for (n = 0; n < LOGGER_NUM_LEVELS; n++)
     {
         strcpy(lname, LOGGER_LEVEL_NAMES[n]);
-        strx_lower_case(lname);
+        xstr_lower_case(lname);
         if (strlen(lname) == len && strcmp(siri.args->log_level, lname) == 0)
         {
             logger_init(stdout, n);
@@ -169,8 +163,8 @@ int siri_start(void)
     uv_loop_init(siri.loop);
 
     /* initialize the back-end-, client- server and load databases */
-    if (    (rc = siri_admin_account_init(&siri)) ||
-            (rc = siri_admin_request_init()) ||
+    if (    (rc = siri_service_account_init(&siri)) ||
+            (rc = siri_service_request_init()) ||
             (rc = sirinet_bserver_init(&siri)) ||
             (rc = sirinet_clserver_init(&siri)) ||
             (rc = SIRI_load_databases()))
@@ -241,11 +235,11 @@ void siri_free(void)
     /* free siridb grammar */
     cleri_grammar_free(siri.grammar);
 
-    /* free siridb administrative accounts */
-    siri_admin_account_destroy(&siri);
+    /* free siridb service accounts */
+    siri_service_account_destroy(&siri);
 
-    /* free siridb admin request */
-    siri_admin_request_destroy();
+    /* free siridb service request */
+    siri_service_request_destroy();
 
     /* free config */
     siri_cfg_destroy(&siri);
index ff6c2f6107b38f91d2c54be8ad8b04617af8b1ab..824cca010ceaef489f623144f3af9699ddcb0653 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * version.c - contains SiriDB version info.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 08-03-2016
- *
+ * version.c - SiriDB version info.
  */
 #include <assert.h>
 #include <siri/version.h>
diff --git a/src/slist/slist.c b/src/slist/slist.c
deleted file mode 100644 (file)
index 2c3c389..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * slist.c - Simple List
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 06-06-2016
- *
- */
-#include <logger/logger.h>
-#include <slist/slist.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define SLIST_MAX_SZ 512
-
-/*
- * Returns NULL in case an error has occurred.
- *
- * In case the size is unknown, SLIST_DEFAULT_SIZE is recommended since in this
- * case we can do a re-allocation with multiples of 64K.
- */
-slist_t * slist_new(size_t size)
-{
-    /* sizeof(slist_t) is 16 bytes, only for len and size and data[] is
-     * excluded.
-     */
-    slist_t * slist = (slist_t *)
-            malloc(sizeof(slist_t) + sizeof(void *) * size);
-
-    if (slist == NULL)
-    {
-        return NULL;
-    }
-    slist->size = size;
-    slist->len = 0;
-    return slist;
-}
-
-/*
- * Returns NULL in case an error has occurred.
- */
-slist_t * slist_copy(slist_t * source)
-{
-    size_t size = sizeof(slist_t) + sizeof(void *) * source->size;
-    slist_t * slist = (slist_t *) malloc(size);
-    if (slist == NULL)
-    {
-        return NULL;
-    }
-    memcpy(slist, source, size);
-    return slist;
-}
-
-/*
- * Returns 0 if successful or -1 in case of an error.
- * (in case of an error the list is unchanged)
- */
-int slist_append_safe(slist_t ** slist, void * data)
-{
-    if ((*slist)->len == (*slist)->size)
-    {
-        slist_t * tmp;
-
-        size_t sz = (*slist)->size;
-
-        /* double the size when > 0 and <  SLIST_MAX_SZ */
-        (*slist)->size = (sz >= SLIST_DEFAULT_SIZE) ?
-                (sz <= SLIST_MAX_SZ) ?
-                        sz * 2 : sz + SLIST_MAX_SZ : SLIST_DEFAULT_SIZE;
-
-        tmp = (slist_t *) realloc(
-                *slist,
-                sizeof(slist_t) + sizeof(void *) * (*slist)->size);
-
-        if (tmp == NULL)
-        {
-            /* an error has occurred */
-            (*slist)->size = sz;
-            return -1;
-        }
-
-        /* overwrite the original value with the new one */
-        *slist = tmp;
-    }
-
-    slist_append((*slist), data);
-
-    return 0;
-}
-
-/*
- * Compact memory used for the slist object when the list has more than
- * SLIST_DEFAULT_SIZE free space. After the compact the list has
- * a size which is SLIST_DEFAULT_SIZE greater than its length.
- */
-void slist_compact(slist_t ** slist)
-{
-    size_t sz = (*slist)->size;
-
-    if (sz - (*slist)->len > SLIST_DEFAULT_SIZE)
-    {
-        slist_t * tmp;
-
-        (*slist)->size = (*slist)->len + SLIST_DEFAULT_SIZE;
-
-        tmp = (slist_t *) realloc(
-                *slist,
-                sizeof(slist_t) + sizeof(void *) * (*slist)->size);
-
-        if (tmp == NULL)
-        {
-            /* an error has occurred; log and restore size */
-            log_error("Error has occurred while re-allocating less space");
-            (*slist)->size = sz;
-        }
-        else
-        {
-            /* overwrite the original value with the new one */
-            *slist = tmp;
-        }
-    }
-}
diff --git a/src/strextra/strextra.c b/src/strextra/strextra.c
deleted file mode 100644 (file)
index 9c69987..0000000
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * strextra.c - Extra String functions used by SiriDB
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 19-03-2016
- *
- */
-#include <ctype.h>
-#include <inttypes.h>
-#include <logger/logger.h>
-#include <math.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-void strx_lower_case(char * sptr)
-{
-   for (; *sptr != '\0'; sptr++)
-        *sptr = tolower( (unsigned char) * sptr);
-}
-
-void strx_upper_case(char * sptr)
-{
-   for (; *sptr != '\0'; sptr++)
-        *sptr = toupper( (unsigned char) * sptr);
-}
-
-void strx_replace_char(char * sptr, char orig, char repl)
-{
-    for (; *sptr != '\0'; sptr++)
-    {
-        if (*sptr == orig)
-        {
-            *sptr = repl;
-        }
-    }
-}
-
-/*
- * Replace all occurrences of 'o' with 'r' in 'str'. We restrict the new size
- * to 'n'.
- *
- * Returns 0 if successful or -1 if the replaced string does not fit. In this
- * case the original string is untouched. The new string is terminated.
- */
-int strx_replace_str(char * str, char * o, char * r, size_t n)
-{
-    char buffer[n];
-    char * pos, * s;
-    size_t l, size = 0, olen = strlen(o), rlen = strlen(r);
-
-    for (s = str; (pos = strstr(s, o)) != NULL; s = pos + olen)
-    {
-        l = pos - s;
-
-        if (size + l + rlen >= n)
-        {
-            return -1;
-        }
-
-        memcpy(buffer + size, s, l);
-        size += l;
-
-        memcpy(buffer + size, r, rlen);
-        size += rlen;
-
-    }
-
-    if (s != str)
-    {
-        memcpy(str, buffer, size);
-        str[size] = '\0';
-    }
-
-    return 0;
-}
-
-/*
- * Split and then join a given string.
- *
- * For example:
- *      string: "  this  is a   test  "
- *      split: ' ' and join with '_'
- *      result: "this_is_a_test"
- */
-void strx_split_join(char * pt, char split_chr, char join_chr)
-{
-    int join = -1;
-    char * dest = pt;
-
-    for (; *pt != '\0'; pt++)
-    {
-        if (*pt != split_chr)
-        {
-            if (join > 0)
-            {
-                *dest = join_chr;
-                dest++;
-            }
-            join = 0;
-            *dest = *pt;
-            dest++;
-        }
-        else if (!join)
-        {
-            join = 1;
-        }
-    }
-
-    *dest = '\0';
-}
-
-void strx_trim(char ** str, char chr)
-{
-    /*
-     * trim: when chr is 0 we will trim whitespace,
-     * otherwise only the given char.
-     */
-    char * end;
-
-    /* trim leading chars  */
-    while ((chr && **str == chr) || (!chr && isspace(**str)))
-    {
-        (*str)++;
-    }
-
-    /* check all chars?  */
-    if(**str == 0)
-    {
-        return;
-    }
-
-    /* trim trailing chars  */
-    end = *str + strlen(*str) - 1;
-    while (end > *str &&
-            ((chr && *end == chr) || (!chr && isspace(*end))))
-    {
-        end--;
-    }
-
-    /* write new null terminator  */
-    *(end + 1) = 0;
-}
-
-/*
- * returns true or false
- */
-bool strx_is_empty(const char * str)
-{
-    const char * test = str;
-    for (; *test; test++)
-    {
-        if (!isspace(*test))
-        {
-            return false;
-        }
-    }
-    return true;
-}
-
-bool strx_is_int(const char * str)
-{
-   /* Handle negative numbers.  */
-   if (*str == '-')
-   {
-       ++str;
-   }
-
-   /* Handle empty string or just "-".  */
-   if (!*str)
-   {
-       return false;
-   }
-
-   /* Check for non-digit chars in the rest of the string.  */
-   while (*str)
-   {
-       if (!isdigit(*str))
-       {
-           return false;
-       }
-       else
-       {
-           ++str;
-       }
-   }
-
-   return true;
-}
-
-bool strx_is_float(const char * str)
-{
-   /* Handle negative numbers.   */
-   if (*str == '-' || *str == '+')
-   {
-       ++str;
-   }
-
-   size_t dots = 0;
-
-   /* Handle empty string or just "-".  */
-   if (!*str)
-   {
-       return false;
-   }
-
-   /* Check for non-digit chars in the rest of the string.  */
-   while (*str)
-   {
-       if (*str == '.')
-       {
-           ++dots;
-       }
-       else if (!isdigit(*str))
-       {
-           return false;
-       }
-
-       ++str;
-   }
-
-   return dots == 1;
-}
-
-bool strx_is_graph(const char * str)
-{
-    for (; *str; str++)
-    {
-        if (!isgraph(*str))
-        {
-            return false;
-        }
-    }
-    return true;
-}
-
-/*
- * This function is used to extra a SiriDB string. These strings start
- * with " or with ' and we should replace double this character in the
- * string with a single one.
- *
- * 'dest' string will be terminated and the return value is the new
- * length of 'dest'.
- */
-size_t strx_extract_string(char * dest, const char * source, size_t len)
-{
-    size_t i = 0;
-
-    /* take the first character, this is " or ' */
-    char chr = *source;
-
-    /* we need to loop till len-2 so take 2 */
-    for (len -= 2; i < len; i++)
-    {
-        source++;
-        if (*source == chr)
-        {
-            /* this is the character, skip one and take the next */
-            source++;
-            len--;
-        }
-        dest[i] = *source;
-    }
-
-    /* set final 0 */
-    dest[i] = 0;
-
-    return i;
-}
-
-/*
- * Returns a string to double.
- * No error checking is done, we make the following assumptions:
- *      - len > 0
- *      - string is allowed to have one dot (.) at most but not required
- *      - string can start with a plus (+) or minus (-) sign.
- */
-double strx_to_double(const char * src, size_t len)
-{
-    char * pt = (char *) src;
-    double d = 0;
-    double convert;
-
-    switch (*pt)
-    {
-    case '-':
-        convert = -1.0;
-        pt++;
-        break;
-    case '+':
-        pt++;
-        /* FALLTHRU */
-        /* no break */
-    default:
-        convert = 1.0;
-    }
-
-    uint64_t r1 = *pt - '0';
-
-    while (--len && isdigit(*(++pt)))
-    {
-        r1 = 10 * r1 + *pt - '0';
-    }
-
-    d = (double) r1;
-
-    if (--len && *(pt++) == '.')
-    {
-        uint64_t r2 = *pt - '0';
-        ssize_t i;
-        for (i = -1; --len && isdigit(*(++pt)); i--)
-        {
-             r2 = 10 * r2 + *pt - '0';
-        }
-
-        d += pow(10, i) * (double) r2;
-    }
-
-    return convert * d;
-}
-
-/*
- * Returns a string to uint64_t.
- * No error checking is done, we make the following assumptions:
- *      - len > 0
- *      - string can only contain characters [0..9] and no signs
- */
-uint64_t strx_to_uint64(const char * src, size_t len)
-{
-    char * pt = (char *) src;
-
-    uint64_t i = *pt - '0';
-
-    while (--len && isdigit(*(++pt)))
-    {
-        i = 10 * i + *pt - '0';
-    }
-
-    return i;
-}
-
-/*
- * Returns a string duplicate like strdup() and set the strlen() to n;
- */
-char * strx_dup(const char * src, size_t * n)
-{
-    *n = strlen(src);
-    char * nstr = (char *) malloc(*n + 1);
-    if (nstr)
-    {
-        memcpy(nstr, src, *n + 1);
-    }
-    return nstr;
-}
index 56549e0c17f5bf9b22bbff0b56b13374acc9f572..135055f30ce4a5d66e847b521cb2079057153b5d 100644 (file)
@@ -1,13 +1,5 @@
 /*
  * timeit.c - Timeit.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 16-03-2016
- *
  */
 #include <timeit/timeit.h>
 #include <time.h>
diff --git a/src/vec/vec.c b/src/vec/vec.c
new file mode 100644 (file)
index 0000000..f2979e1
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * vec.c - Vector List.
+ */
+#include <logger/logger.h>
+#include <vec/vec.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define VEC_MAX_SZ 512
+
+/*
+ * Returns NULL in case an error has occurred.
+ *
+ * In case the size is unknown, VEC_DEFAULT_SIZE is recommended since in this
+ * case we can do a re-allocation with multiples of 64K.
+ */
+vec_t * vec_new(size_t size)
+{
+    /* sizeof(vec_t) is 16 bytes, only for len and size and data[] is
+     * excluded.
+     */
+    vec_t * vec = (vec_t *)
+            malloc(sizeof(vec_t) + sizeof(void *) * size);
+
+    if (vec == NULL)
+    {
+        return NULL;
+    }
+    vec->size = size;
+    vec->len = 0;
+    return vec;
+}
+
+/*
+ * Returns NULL in case an error has occurred.
+ */
+vec_t * vec_copy(vec_t * source)
+{
+    size_t size = sizeof(vec_t) + sizeof(void *) * source->size;
+    vec_t * vec = (vec_t *) malloc(size);
+    if (vec == NULL)
+    {
+        return NULL;
+    }
+    memcpy(vec, source, size);
+    return vec;
+}
+
+/*
+ * Returns 0 if successful or -1 in case of an error.
+ * (in case of an error the list is unchanged)
+ */
+int vec_append_safe(vec_t ** vec, void * data)
+{
+    if ((*vec)->len == (*vec)->size)
+    {
+        vec_t * tmp;
+
+        size_t sz = (*vec)->size;
+
+        /* double the size when > 0 and <  VEC_MAX_SZ */
+        (*vec)->size = (sz >= VEC_DEFAULT_SIZE) ?
+                (sz <= VEC_MAX_SZ) ?
+                        sz * 2 : sz + VEC_MAX_SZ : VEC_DEFAULT_SIZE;
+
+        tmp = (vec_t *) realloc(
+                *vec,
+                sizeof(vec_t) + sizeof(void *) * (*vec)->size);
+
+        if (tmp == NULL)
+        {
+            /* an error has occurred */
+            (*vec)->size = sz;
+            return -1;
+        }
+
+        /* overwrite the original value with the new one */
+        *vec = tmp;
+    }
+
+    vec_append((*vec), data);
+
+    return 0;
+}
+
+/*
+ * Compact memory used for the vec object when the list has more than
+ * VEC_DEFAULT_SIZE free space. After the compact the list has
+ * a size which is VEC_DEFAULT_SIZE greater than its length.
+ */
+void vec_compact(vec_t ** vec)
+{
+    size_t sz = (*vec)->size;
+
+    if (sz - (*vec)->len > VEC_DEFAULT_SIZE)
+    {
+        vec_t * tmp;
+
+        (*vec)->size = (*vec)->len + VEC_DEFAULT_SIZE;
+
+        tmp = (vec_t *) realloc(
+                *vec,
+                sizeof(vec_t) + sizeof(void *) * (*vec)->size);
+
+        if (tmp == NULL)
+        {
+            /* an error has occurred; log and restore size */
+            log_error("Error has occurred while re-allocating less space");
+            (*vec)->size = sz;
+        }
+        else
+        {
+            /* overwrite the original value with the new one */
+            *vec = tmp;
+        }
+    }
+}
index 328c72a04767c1cf248165a2a8103b81e48b7b4e..03a2687847a0c23a23b91120d47a2f60a44f61af 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * xmath.c - Extra math functions which are useful.
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 12-03-2016
- *
+ * xmath.c - Extra math functions functions used by SiriDB.
  */
 #include <xmath/xmath.h>
 #include <stdarg.h>
index 04c4e23772b857bc0fd2f308b48389ff359e8a71..949efd3282a759d8473f37475cd2a4b007c1ea7c 100644 (file)
@@ -1,13 +1,5 @@
 /*
- * xpath.c - Path and file tools
- *
- * author       : Jeroen van der Heijden
- * email        : jeroen@transceptor.technology
- * copyright    : 2016, Transceptor Technology
- *
- * changes
- *  - initial version, 15-07-2016
- *
+ * xpath.c - Path and file tools.
  */
 #include <limits.h>
 #include <logger/logger.h>
diff --git a/src/xstr/xstr.c b/src/xstr/xstr.c
new file mode 100644 (file)
index 0000000..358c425
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * xstr.c - Extra String functions used by SiriDB.
+ */
+#include <ctype.h>
+#include <inttypes.h>
+#include <logger/logger.h>
+#include <math.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void xstr_lower_case(char * sptr)
+{
+   for (; *sptr != '\0'; sptr++)
+        *sptr = tolower( (unsigned char) * sptr);
+}
+
+void xstr_upper_case(char * sptr)
+{
+   for (; *sptr != '\0'; sptr++)
+        *sptr = toupper( (unsigned char) * sptr);
+}
+
+void xstr_replace_char(char * sptr, char orig, char repl)
+{
+    for (; *sptr != '\0'; sptr++)
+    {
+        if (*sptr == orig)
+        {
+            *sptr = repl;
+        }
+    }
+}
+
+/*
+ * Replace all occurrences of 'o' with 'r' in 'str'. We restrict the new size
+ * to 'n'.
+ *
+ * Returns 0 if successful or -1 if the replaced string does not fit. In this
+ * case the original string is untouched. The new string is terminated.
+ */
+int xstr_replace_str(char * str, char * o, char * r, size_t n)
+{
+    char buffer[n];
+    char * pos, * s;
+    size_t l, size = 0, olen = strlen(o), rlen = strlen(r);
+
+    for (s = str; (pos = strstr(s, o)) != NULL; s = pos + olen)
+    {
+        l = pos - s;
+
+        if (size + l + rlen >= n)
+        {
+            return -1;
+        }
+
+        memcpy(buffer + size, s, l);
+        size += l;
+
+        memcpy(buffer + size, r, rlen);
+        size += rlen;
+
+    }
+
+    if (s != str)
+    {
+        memcpy(str, buffer, size);
+        str[size] = '\0';
+    }
+
+    return 0;
+}
+
+/*
+ * Split and then join a given string.
+ *
+ * For example:
+ *      string: "  this  is a   test  "
+ *      split: ' ' and join with '_'
+ *      result: "this_is_a_test"
+ */
+void xstr_split_join(char * pt, char split_chr, char join_chr)
+{
+    int join = -1;
+    char * dest = pt;
+
+    for (; *pt != '\0'; pt++)
+    {
+        if (*pt != split_chr)
+        {
+            if (join > 0)
+            {
+                *dest = join_chr;
+                dest++;
+            }
+            join = 0;
+            *dest = *pt;
+            dest++;
+        }
+        else if (!join)
+        {
+            join = 1;
+        }
+    }
+
+    *dest = '\0';
+}
+
+void xstr_trim(char ** str, char chr)
+{
+    /*
+     * trim: when chr is 0 we will trim whitespace,
+     * otherwise only the given char.
+     */
+    char * end;
+
+    /* trim leading chars  */
+    while ((chr && **str == chr) || (!chr && isspace(**str)))
+    {
+        (*str)++;
+    }
+
+    /* check all chars?  */
+    if(**str == 0)
+    {
+        return;
+    }
+
+    /* trim trailing chars  */
+    end = *str + strlen(*str) - 1;
+    while (end > *str &&
+            ((chr && *end == chr) || (!chr && isspace(*end))))
+    {
+        end--;
+    }
+
+    /* write new null terminator  */
+    *(end + 1) = 0;
+}
+
+/*
+ * returns true or false
+ */
+bool xstr_is_empty(const char * str)
+{
+    const char * test = str;
+    for (; *test; test++)
+    {
+        if (!isspace(*test))
+        {
+            return false;
+        }
+    }
+    return true;
+}
+
+bool xstr_is_int(const char * str)
+{
+   /* Handle negative numbers.  */
+   if (*str == '-')
+   {
+       ++str;
+   }
+
+   /* Handle empty string or just "-".  */
+   if (!*str)
+   {
+       return false;
+   }
+
+   /* Check for non-digit chars in the rest of the string.  */
+   while (*str)
+   {
+       if (!isdigit(*str))
+       {
+           return false;
+       }
+       else
+       {
+           ++str;
+       }
+   }
+
+   return true;
+}
+
+bool xstr_is_float(const char * str)
+{
+   /* Handle negative numbers.   */
+   if (*str == '-' || *str == '+')
+   {
+       ++str;
+   }
+
+   size_t dots = 0;
+
+   /* Handle empty string or just "-".  */
+   if (!*str)
+   {
+       return false;
+   }
+
+   /* Check for non-digit chars in the rest of the string.  */
+   while (*str)
+   {
+       if (*str == '.')
+       {
+           ++dots;
+       }
+       else if (!isdigit(*str))
+       {
+           return false;
+       }
+
+       ++str;
+   }
+
+   return dots == 1;
+}
+
+bool xstr_is_graph(const char * str)
+{
+    for (; *str; str++)
+    {
+        if (!isgraph(*str))
+        {
+            return false;
+        }
+    }
+    return true;
+}
+
+/*
+ * This function is used to extra a SiriDB string. These strings start
+ * with " or with ' and we should replace double this character in the
+ * string with a single one.
+ *
+ * 'dest' string will be terminated and the return value is the new
+ * length of 'dest'.
+ */
+size_t xstr_extract_string(char * dest, const char * source, size_t len)
+{
+    size_t i = 0;
+
+    /* take the first character, this is " or ' */
+    char chr = *source;
+
+    /* we need to loop till len-2 so take 2 */
+    for (len -= 2; i < len; i++)
+    {
+        source++;
+        if (*source == chr)
+        {
+            /* this is the character, skip one and take the next */
+            source++;
+            len--;
+        }
+        dest[i] = *source;
+    }
+
+    /* set final 0 */
+    dest[i] = 0;
+
+    return i;
+}
+
+/*
+ * Returns a string to double.
+ * No error checking is done, we make the following assumptions:
+ *      - len > 0
+ *      - string is allowed to have one dot (.) at most but not required
+ *      - string can start with a plus (+) or minus (-) sign.
+ */
+double xstr_to_double(const char * src, size_t len)
+{
+    char * pt = (char *) src;
+    double d = 0;
+    double convert;
+
+    switch (*pt)
+    {
+    case '-':
+        convert = -1.0;
+        pt++;
+        break;
+    case '+':
+        pt++;
+        /* FALLTHRU */
+        /* no break */
+    default:
+        convert = 1.0;
+    }
+
+    uint64_t r1 = *pt - '0';
+
+    while (--len && isdigit(*(++pt)))
+    {
+        r1 = 10 * r1 + *pt - '0';
+    }
+
+    d = (double) r1;
+
+    if (--len && *(pt++) == '.')
+    {
+        uint64_t r2 = *pt - '0';
+        ssize_t i;
+        for (i = -1; --len && isdigit(*(++pt)); i--)
+        {
+             r2 = 10 * r2 + *pt - '0';
+        }
+
+        d += pow(10, i) * (double) r2;
+    }
+
+    return convert * d;
+}
+
+/*
+ * Returns a string to uint64_t.
+ * No error checking is done, we make the following assumptions:
+ *      - len > 0
+ *      - string can only contain characters [0..9] and no signs
+ */
+uint64_t xstr_to_uint64(const char * src, size_t len)
+{
+    char * pt = (char *) src;
+
+    uint64_t i = *pt - '0';
+
+    while (--len && isdigit(*(++pt)))
+    {
+        i = 10 * i + *pt - '0';
+    }
+
+    return i;
+}
+
+/*
+ * Returns a string duplicate like strdup() and set the strlen() to n;
+ */
+char * xstr_dup(const char * src, size_t * n)
+{
+    *n = strlen(src);
+    char * nstr = (char *) malloc(*n + 1);
+    if (nstr)
+    {
+        memcpy(nstr, src, *n + 1);
+    }
+    return nstr;
+}
index 0e8f9f41f20ce43fdddd4b734fff2be516c1430d..ffb67f70ed60a01d9f73b583f2d6331fa3416642 100644 (file)
@@ -5,7 +5,7 @@
 ../src/siri/db/re.c
 ../src/siri/err.c
 ../src/qpack/qpack.c
-../src/slist/slist.c
+../src/vec/vec.c
 ../src/cexpr/cexpr.c
-../src/strextra/strextra.c
+../src/xstr/xstr.c
 ../src/logger/logger.c
index 3157e57137a8570d109dc703508b246e47148d63..a6341a118307943316a388d2279a82b68be1485b 100644 (file)
@@ -1,3 +1,3 @@
 ../src/imap/imap.c
-../src/slist/slist.c
+../src/vec/vec.c
 ../src/logger/logger.c
\ No newline at end of file
index a9f2c3d63da133665f225e5c2614400a8e70e934..d2e6834f5b553022c784011d1434d10001106cc3 100644 (file)
@@ -52,7 +52,7 @@ static imap_t * imap_tmp;
 
 static int test__imap_decref_cb(char * series)
 {
-    ((slist_object_t *) series)->ref--;
+    ((vec_object_t *) series)->ref--;
     return 1;
 }
 
index 6a97c9ba404230c585dc595c79504fc0aff2e761..e6b944a3b9f76520b819ddcd4e41079497fe4979 100644 (file)
@@ -1,4 +1,4 @@
-../src/slist/slist.c
+../src/vec/vec.c
 ../src/ctree/ctree.c
 ../src/xpath/xpath.c
 ../src/xmath/xmath.c
@@ -6,7 +6,7 @@
 ../src/imap/imap.c
 ../src/llist/llist.c
 ../src/logger/logger.c
-../src/strextra/strextra.c
+../src/xstr/xstr.c
 ../src/cfgparser/cfgparser.c
 ../src/owcrypt/owcrypt.c
 ../src/cexpr/cexpr.c
@@ -73,9 +73,9 @@
 ../src/siri/db/walker.c
 ../src/siri/file/handler.c
 ../src/siri/file/pointer.c
-../src/siri/admin/account.c
-../src/siri/admin/client.c
-../src/siri/admin/request.c
+../src/siri/service/account.c
+../src/siri/service/client.c
+../src/siri/service/request.c
 ../src/siri/help/help.c
 ../src/siri/cfg/cfg.c
 ../src/siri/grammar/grammar.c
\ No newline at end of file
index 7a3451618022f3cab140b74193413f93545dfccd..fac9e8a4a21d953edd22803749f962f12e90d5f2 100644 (file)
@@ -1,2 +1,2 @@
-../src/slist/slist.c
+../src/vec/vec.c
 ../src/logger/logger.c
\ No newline at end of file
index ef5c1b03a403e7134825e94c12f41372fe875ae3..c3d25f442ef944f49b165adfedbcaa16c480b00c 100644 (file)
@@ -1,5 +1,5 @@
 #include "../test.h"
-#include <slist/slist.h>
+#include <vec/vec.h>
 
 const unsigned int num_entries = 14;
 char * entries[] = {
@@ -21,56 +21,56 @@ char * entries[] = {
 
 int main()
 {
-    test_start("slist");
+    test_start("vec");
 
-    /* slist_append_safe */
+    /* vec_append_safe */
     {
-        slist_t * slist = slist_new(0);
-        _assert (slist->len == 0);
-        _assert (slist->size == 0);
+        vec_t * vec = vec_new(0);
+        _assert (vec->len == 0);
+        _assert (vec->size == 0);
 
         unsigned int i;
         for (i = 0; i < num_entries; i++)
         {
-            _assert (slist_append_safe(&slist, entries[i]) == 0);
+            _assert (vec_append_safe(&vec, entries[i]) == 0);
         }
 
-        /* slist_copy */
+        /* vec_copy */
         {
-            slist_t * slistcp = slist_copy(slist);
+            vec_t * veccp = vec_copy(vec);
             unsigned int i;
             for (i = 0; i < num_entries; i++)
             {
-                _assert (slistcp->data[i] == entries[i]);
+                _assert (veccp->data[i] == entries[i]);
             }
-            slist_free(slistcp);
+            vec_free(veccp);
         }
 
-        _assert (slist->len == num_entries);
-        slist_free(slist);
+        _assert (vec->len == num_entries);
+        vec_free(vec);
     }
 
-    /* slist_append */
+    /* vec_append */
     {
-        slist_t * slist = slist_new(num_entries);
-        _assert (slist->len == 0);
-        _assert (slist->size == num_entries);
+        vec_t * vec = vec_new(num_entries);
+        _assert (vec->len == 0);
+        _assert (vec->size == num_entries);
 
         unsigned int i;
         for (i = 0; i < num_entries; i++)
         {
-            slist_append(slist, entries[i]);
+            vec_append(vec, entries[i]);
         }
 
-        _assert (slist->len == num_entries);
+        _assert (vec->len == num_entries);
 
-        /* slist_pop */
+        /* vec_pop */
         for (i = num_entries; i-- > 0;)
         {
-            _assert (slist_pop(slist) == entries[i]);
+            _assert (vec_pop(vec) == entries[i]);
         }
 
-        slist_free(slist);
+        vec_free(vec);
     }
 
 
diff --git a/test/test_strx/sources b/test/test_strx/sources
deleted file mode 100644 (file)
index f82c483..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/strextra/strextra.c
diff --git a/test/test_strx/test_strx.c b/test/test_strx/test_strx.c
deleted file mode 100644 (file)
index 8ddc7e5..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "../test.h"
-#include <strextra/strextra.h>
-
-
-int main()
-{
-    test_start("strx");
-
-    /* strx_to_double */
-    {
-        _assert (strx_to_double("0.5", 3) == 0.5);
-        _assert (strx_to_double("0.55", 3) == 0.5);
-        _assert (strx_to_double("123.456", 7) == 123.456);
-        _assert (strx_to_double("123", 3) == 123);
-        _assert (strx_to_double("123.", 4) == 123);
-        _assert (strx_to_double("123456.", 3) == 123);
-        _assert (strx_to_double("-0.5", 3) == -0.5);
-    }
-
-    return test_end();
-}
diff --git a/test/test_xstr/sources b/test/test_xstr/sources
new file mode 100644 (file)
index 0000000..7940091
--- /dev/null
@@ -0,0 +1 @@
+../src/xstr/xstr.c
diff --git a/test/test_xstr/test_xstr.c b/test/test_xstr/test_xstr.c
new file mode 100644 (file)
index 0000000..6e88343
--- /dev/null
@@ -0,0 +1,21 @@
+#include "../test.h"
+#include <xstr/xstr.h>
+
+
+int main()
+{
+    test_start("xstr");
+
+    /* xstr_to_double */
+    {
+        _assert (xstr_to_double("0.5", 3) == 0.5);
+        _assert (xstr_to_double("0.55", 3) == 0.5);
+        _assert (xstr_to_double("123.456", 7) == 123.456);
+        _assert (xstr_to_double("123", 3) == 123);
+        _assert (xstr_to_double("123.", 4) == 123);
+        _assert (xstr_to_double("123456.", 3) == 123);
+        _assert (xstr_to_double("-0.5", 3) == -0.5);
+    }
+
+    return test_end();
+}